darga333 Posted April 26, 2006 Share Posted April 26, 2006 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 variablesI have done it this way because I want to keep my email template separate from the codeall 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? Quote Link to comment https://forums.phpfreaks.com/topic/8512-trouble-including-php-in-an-email/ Share on other sites More sharing options...
KrisNz Posted April 26, 2006 Share Posted April 26, 2006 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.htmlDear %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 https://forums.phpfreaks.com/topic/8512-trouble-including-php-in-an-email/#findComment-31172 Share on other sites More sharing options...
darga333 Posted April 27, 2006 Author Share Posted April 27, 2006 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.htmlDear %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] Quote Link to comment https://forums.phpfreaks.com/topic/8512-trouble-including-php-in-an-email/#findComment-31176 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.