Name: swati Date: July 20, 2005 at 09:13:30 Pacific Subject: How to email a report OS: Win XP CPU/Ram: pentium 256mb ram
Comment:
Hi, I have a report generated thru the foll php script that appears on my screen.I want to email this report without using the file /send feature of any email program but directly from the page itself using a php script that says ' email this report to a/b/c/d or whoever.
I am not too familiar with php .I can do the send mail bit(see below) but do i insert it at the bottom of the php file that i have pasted above which is called temptrip.php. And if I do then does the $message = "temptrip.php" bit work ?
Or any other suggestions ? <?php $result2 = mysql_query("SELECT * FROM `users` WHERE x='$x'"); $myrow2 = mysql_fetch_array($result2);
$current=(date("l F d, Y")); if ( $send_mail == 1 ) { $to_mail = "abc@abc.com"; $subject = "Trip Details Submitted On:".$current." By ".$x." (".$myrow2["y"]." ".$myrow2["z"].") "; $message = " temptrip.php "
do i insert it at the bottom of the php file that i have pasted above which is called temptrip.php. And if I do then does the $message = "temptrip.php" bit work ?
It's best if you fill $message one by one, on each desired output, which will be different from the web output (e.g.: no html tags).
After all desired output is placed into $message, then you can do mail() at the bottom (in the same script - temptrip.php).
You can probably just put the whole temptrip.php into $message, but I think you must tell PHP to read the file normally like a web browser do, and not by simply doing $message = "temptrip.php"; but then the html tags will also be put into $message.
You can then probably strip html tags from $message (there's a PHP function for it) but still, I think it's better if you put values into $message directly in temptrip.php, slowly one by one after each output is produced.
Who made that mailer script? If it's not you, can't you ask him/her to fix it? Because as I said above, if I try to write a script for you then there'll be too many possibilities for error (and confusion). Like your temptrip.php overthere, where's the opening html tag? It's best if you can ask someone whom you can trust to test things directly on your server, along with the database connection, etc. :)
But of course you can keep asking questions in here, especially if you're trying to fix it yourself. If the question is clear and specific enough, lots of people here will help :)
hi, the guy who set it up is not working here anymore so i am bug fixer in charge ! Pl. do let me know what the $message= should read as. I didnt put in the html tags because i thot it wasnt relevant to my query- clearly i was wrong ! Thanks !
Replace your@email.com with your email, save and upload the file.
open it from your browser, wait for a moment and check the email (check the bulk/spam folder also). See if the email got sent, then post back here.
I dont use anything from your 2nd script because I think it should be included somewhere, the script won't work by itself. Like where'd $x got defined (in the 2nd script)?
a. I did backup temptrip. b. You understood my reqt. correctly. c. The email got sent from 'apache' ..as below: d. Now how do I get the contents of the report and the correct from-mail id to appear ?
From "Apache" <apache@abc.def.com> Subject Trip Details Submitted On: Saturday July 23, 2005 Date Sat, July 23, 2005 10:13 am To abc@xyz.com
Hi, I got the from-mail id set up (see below) but the time is not showing up( not really relevant but its a bother !) and ofcourse the rest of the actual report.
<?php $to = "abc@def.com"; $subject = "Trip Details Submitted On: " . date("l F d, Y", time ()); $from = "form@def.com"; $message = "Monthly Report
You mean on the subject? On your script on Response #8? Now that's weird :( date("l F d, Y", time ()) should always produce current time in GMT (according to server settings) no matter what.
But anyways, you may try to modify temptrip.php into this below. Remember, I only modify things you paste. So if there's some more code above, don't delete them:
If the above works, you can add or remove spaces on the added code above, and view the email in proportional font (like courier) so it'll be easier to read
Sending HTML email is actually not very hard to do, especially if you're the only one who'll read the email (and thus you'll know to read it in an HTML email client). But let's discuss that on another topic :D
a.) The time doesnt appear in the subject line. (See below)
Subject: Trip Details Submitted On: Sunday July 24, 2005 From: form@def.com Date: Sun, July 24, 2005 12:40 am To: abc@def.com
The php script i have for this is :
$subject = "Trip Details Submitted On: " . date("l F d, Y", time ());
b.)I got all the data to appear on the email but sometimes the trip info is a long sentence which then means the page formatting doesnt remain A4 with all fields coming up on a single line but spilling over to the next. This wouldnt be a problem if I could do a wrap text and have the email come in a grid form.Any pointers ?
c.)Another thing: I was wondering if there is anyway I could see the report and then email it without creating another php file ? Basically, if I could put a line like - 'click here to email this page' without it having to get processed into another page...
Again, many many thanks for all the help you have been giving me.
a) ah, you mean _the_ time, here's to show date and time:
date("l F d, Y - g:i a", time ());
Look here, I think you can then customize the format to suits you best.
b) Yes, it's a "problem" on plain text email. You should use HTML then.
This temptrip.php is hopefully works to send an HTML e-mail.
c) It is possible to be done in that 1 file. But as there're still some parts missing, like the form (that defines $month & $year), etc, I can't help you.
Maybe it's easier to create another file let's say temptripmailer.php, Which looks exactly like temptrip.php but not a single output thrown to the screen, by removing all shown html tags (not the ones in $message), all echos, and all printf()...
Then you may echo 'Thank you, e-mail sent!';
At the temptrip.php, you need to create a link to temptripmailer.php, which will pass the same $_POST as in temptrip.php itself, and also any needed variables.
:::::
Can the site use session? If so then it might be easier for me to give example of normal temptrip.php with links to temptripmailer.php, and also the temptripmailer.php itself...
with session, I can put $message into a session and pass it to temptripmailer.php without the need of a form, etc.
I still don't know a simple way to call temptripmailer.php by the code you've pasted above without using session. You must use session. Otherwise, some javascript will be required and I'm more confident with PHP.
Session is (i think) available with all PHP. So basically you must call this function:
session_start();
on each pageload.
If the temptrip.php is called directly, you can add that line at the top of the script, before anything sent to the browser, not even a single space. If the top of the script are HTML tags, then add this line on topmost of it:
<?php session_start(); ?>
If all navigations on your site is only calling for a single file, let's say index.php (and all other files are called/managed from within that file), it'll be easier... Just add session_start(); on top of index.php
Look at the file in the address bar when you're viewing codes in temptrip.php and temptripform.php, that's the main file.
:::::
After that, open up the last temptrip.php (I assume it worked) and modify the mailer part at the bottom:
// then, don't do the mail, but put data into session instead // the session names are not the same with var names to saves troubles when // you have register_globals on $_SESSION['themail_to'] = $to; $_SESSION['themail_subject'] = $subject; $_SESSION['themail_headers'] = $headers; $_SESSION['themail_message'] = $message; ?>
Then you add this line somewhere in the views of temptrip.php:
<a href="temptripmailer.php">Send this report to e-mail</a>
hi, I have been sick the past few days - just about recovered enough to look at a screen without my eyes blurring. the html mail did not work. foll. is what i did and couldnt figure what went wrong because i dont get the email although matter appears on screen.
I tested out sending HTML email with that code, and it's accepted perfectly (not in bulk) by Yahoo and Gmail (and outlook of course).
The difference in my testing code is, I don't put anything from your script, so it's only the table header and sample hardcoded rows.
So maybe I've made a mistake when trying to create the looping row from your code.
Sorry, it's really hard to do when I can't test anything :D But basically the concept is the same with the looping in the plain text e-mail, only now it created table rows instead of the looped output only.