Jump to content

Archived

This topic is now archived and is closed to further replies.

darga333

trouble including php in an email

Recommended Posts

This is a bit interesting..

I have two files:

1. The script to gather all of the email addresses and gets the data that is going to be included in the template.
2. The template of the email which includes php variables

I have done it this way because I want to keep my email template separate from the code

all of the data that i want to email is included in mailer_template.php.

You would think hey this is easy.. set $message = file_get_contents('mailer_template.php');
and then just type mail("$email","$subject","$message","$headers");

but that doesnt work because there are php variables inside mailer_template.php (that arent getting displayed in the emails).

the goal here is to have mailer_template.php to be able to include php variables

how do you assign mailer_template.php to the variable $message so that it still includes data from the database?

Share this post


Link to post
Share on other sites
If you want to keep your code separate from your template then you shouldn't have php in it. Use placeholders in your template for the pieces of the email that are going to change.

e.g
[code]
#template.html
Dear %NAME%, thanks for registering with %SITENAME%

#code

$personsName = "Bob";
$siteName = "foo.bar";
$body = file_get_contents("template.html");
$body = str_replace("%NAME%",$personsName,$body);
$body = str_replace("%SITENAME%",$siteName,$body);

[/code]

Share this post


Link to post
Share on other sites
Hey thank you so much! I had no idea that you could even do that!

It works now!

[!--quoteo(post=369073:date=Apr 26 2006, 07:56 PM:name=KrisNz)--][div class=\'quotetop\']QUOTE(KrisNz @ Apr 26 2006, 07:56 PM) [snapback]369073[/snapback][/div][div class=\'quotemain\'][!--quotec--]
If you want to keep your code separate from your template then you shouldn't have php in it. Use placeholders in your template for the pieces of the email that are going to change.

e.g
[code]
#template.html
Dear %NAME%, thanks for registering with %SITENAME%

#code

$personsName = "Bob";
$siteName = "foo.bar";
$body = file_get_contents("template.html");
$body = str_replace("%NAME%",$personsName,$body);
$body = str_replace("%SITENAME%",$siteName,$body);

[/code]
[/quote]

Share this post


Link to post
Share on other sites

×

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.