Jump to content

include php file in mail message


sccot

Recommended Posts

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"

Link to comment
Share on other sites

 $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!

 

 

Link to comment
Share on other sites

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

Link to comment
Share on other sites

  • 1 year later...

$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 by clover23
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.