Board index   FAQ   Search  
Register  Login
Board index php forum :: php coding PHP coding => Mail

Displaying contents of processed PHP page as body in E-Mail

the mail() function

Moderators: macek, egami, gesf

Displaying contents of processed PHP page as body in E-Mail

Postby gbfar » Tue Aug 16, 2005 10:47 am

Hello guys,

:help:

I do need help. I had been looking for something where I could find how to attach a processed PHP page into the body part of the email but couldn't find one. I have a PHP page which displays the results of a certain query. I wish to include that whole PHP page (including images on that page) into the mail. Is it possible that when the email is sent it processes the page before actually including it or it has to be generated before it could be included?

Already thanks!

gb
gbfar
New php-forum User
New php-forum User
 
Posts: 24
Joined: Tue Aug 16, 2005 10:40 am

Postby Alexej Kubarev » Tue Aug 16, 2005 1:12 pm

ob_start() ob_clean() ob_get_content() are your best friends in that case
learn more at php.net
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län

Postby simon44 » Wed Aug 17, 2005 7:02 am

Have a look at my post for my Internet Explorer/Outlook email problem -

http://www.php-forum.com/p/viewtopic.php?t=6470

your difficulty sounds similar - you might be able to use some of the code.


Simon
simon44
New php-forum User
New php-forum User
 
Posts: 4
Joined: Wed Jun 29, 2005 6:15 am

Postby gbfar » Thu Aug 18, 2005 7:04 am

Thanks Guys!

I actually was able to send the whole page. All I did was to open that file with fopen while passing the variable into it and it worked out perfectly. Here is the code-

Code: Select all
<?php
   $e_mail_subject = "something";
   
   $handle = fopen ("http://www.someabsolutefilename?variablename=$variablevalue", "r");
   while (!feof ($handle)) {
      $buffer = fgets($handle, 4096);
      $reply .= $buffer;
   }
   fclose ($handle);

   $mime_boundary = "<<<--GB--" . rand(10000,32000) . "-" . rand(10000,32000) . "--BG-->>>";
   
   $headers .= "From: $call_employee <$call_emp_email>\r\n";
   $headers .= "To: $v_call_contact <$v_call_email>\r\n";
   $headers .= "Bcc: $call_employee <$call_emp_email>, AnotherOne <another email>\r\n";

   $headers .= "MIME-Version: 1.0\r\n";
   $headers .= "Content-Type: multipart/mixed;\r\n";
   $headers .= " boundary=\"".$mime_boundary."\"";

   $message .= "This is a multi-part message in MIME format.\r\n";
   $message .= "\r\n";
   $message .= "--".$mime_boundary."\r\n";

   $message .= "Content-Type: text/html; charset=\"iso-8859-1\"\r\n";
   $message .= "Content-Transfer-Encoding: 7bit\r\n";
   $message .= "\r\n";

   $message .= $reply;

   $message .= "\r\n";
   $message .= "--".$mime_boundary."\r\n";

?>

And that's it, using the simple mail() function of PHP it went on!!!

Enjoy!

GB
gbfar
New php-forum User
New php-forum User
 
Posts: 24
Joined: Tue Aug 16, 2005 10:40 am

Postby Alexej Kubarev » Thu Aug 18, 2005 10:45 am

Please use the code tags when posting the code.. youtr post has been edited..
User avatar
Alexej Kubarev
Site Admin
Site Admin
 
Posts: 2223
Joined: Fri Mar 05, 2004 7:15 am
Location: Täby, Stockholms län


Return to PHP coding => Mail

Who is online

Users browsing this forum: No registered users and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.

cron