Jump to content

trouble including php in an email


darga333

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?

Link to comment
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]
Link to comment
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]
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.