sccot Posted July 13, 2011 Share Posted July 13, 2011 Hey guys is there any way how to include processed php file in message body variable eg ($message) and send via email? Quote Link to comment Share on other sites More sharing options...
requinix Posted July 13, 2011 Share Posted July 13, 2011 Yes, with output buffering. ob_start(); include "file.php"; $content = ob_get_clean(); // then include $content in your $message The file is an actual PHP file with actual PHP code, right? Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 13, 2011 Share Posted July 13, 2011 you can also simply set the include to a variable... $message = include 'test.php'; however I myself would prefer requinix method with output buffering Quote Link to comment Share on other sites More sharing options...
DavidAM Posted July 13, 2011 Share Posted July 13, 2011 you can also simply set the include to a variable... $message = include 'test.php'; however I myself would prefer requinix method with output buffering Not quite (see include): Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. Without using the output buffering (ob_start(), etc), any output of the script is sent to the browser (or stdout). However, if you use: $foo = include('myfile.php'); $foo will receive true or false (depending on the success of the include); unless the included file executes a return('some value here');; in which case the returned value is assigned to $foo. Sounds confusing, so let's show an example: incSource.php <?php print('<H1>Hello World</H1>'); return('Fooled You'); main.php ob_start(); include "incSource.php"; $content = ob_get_clean(); # $content now contains "<H1>Hello World</H1>" $message = include 'incSource.php'; # $message now contains "Fooled You" Quote Link to comment Share on other sites More sharing options...
sccot Posted July 13, 2011 Author Share Posted July 13, 2011 $subject_c = "Your purchased items on website"; $email_c = $od_email; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Bcc: email@gmail.com' . "\r\n"; ob_start(); include 'emailmsg.php'; $content = ob_get_clean(); $message_c = "<h2>Thanks for buying. </h2>" . $content; mail($email_c, $subject_c, $message_c, $headers); Heres my code. And it works. Thanks guys! Quote Link to comment Share on other sites More sharing options...
AyKay47 Posted July 14, 2011 Share Posted July 14, 2011 you can also simply set the include to a variable... $message = include 'test.php'; however I myself would prefer requinix method with output buffering Not quite (see include): Handling Returns: It is possible to execute a return() statement inside an included file in order to terminate processing in that file and return to the script which called it. Also, it's possible to return values from included files. Without using the output buffering (ob_start(), etc), any output of the script is sent to the browser (or stdout). However, if you use: $foo = include('myfile.php'); $foo will receive true or false (depending on the success of the include); unless the included file executes a return('some value here');; in which case the returned value is assigned to $foo. Sounds confusing, so let's show an example: incSource.php <?php print('<H1>Hello World</H1>'); return('Fooled You'); main.php ob_start(); include "incSource.php"; $content = ob_get_clean(); # $content now contains "<H1>Hello World</H1>" $message = include 'incSource.php'; # $message now contains "Fooled You" yes you're right thank you for pointing out my error...I forgot that a return needs to be used in order to get the desired results here...not realistic in this case..thanks again Quote Link to comment Share on other sites More sharing options...
clover23 Posted May 25, 2013 Share Posted May 25, 2013 (edited) $subject_c = "Your purchased items on website"; $email_c = $od_email; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'Bcc: email@gmail.com' . "\r\n"; ob_start(); include 'emailmsg.php'; $content = ob_get_clean(); $message_c = "<h2>Thanks for buying. </h2>" . $content; mail($email_c, $subject_c, $message_c, $headers);Heres my code. And it works. Thanks guys! Hope someone will still have a look on this thread. I have tried what Scott tried but I get an email with Thanks for buying. The $content results are not displayed. What I actually is when a customer order, he receive an email saying thank you. Then, from the cms I approve the transaction or deny it. When I approve it, a php file is executed and he receive the email with order detail and status of it. What Im trying to do is when he place the order and receive the "thank you" email, I want to receive an email with the order details. So far I have these lines and still.. it doesnt work. A friend told me I need to do a POST after but I have no idea how to do it: send_mail(array(array('email'=>$row['email'], 'name'=>$row['name'])), $subject, $_); #this one send email to customer saying Thank you for your order. The order_mail.php file is included above the line, along with other variables. ob_start(); include "order_mail.php"; $content = ob_get_clean(); $message = $content; send_mail( array( array('email' => 'myemail@gmail.com', 'name' => post('name')) ), 'New Order', $message ); #this one should send me an email with order details but it doesnt. Edited May 25, 2013 by clover23 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.