sinikorsurf Posted March 26, 2010 Share Posted March 26, 2010 I have a script that I am using to process form data and send a custom email based on the variables sent by the form. I've spent a couple days trying to get this to work with no luck. This is my first post ever to a PHP forum, and I'm anxious to see if someone will be able to help me out with this issue. Here is the code I am using now, but the php script within the email does not seem to work (One other note I'd like to mention is that the Blind Carbon Copy BCC email does not get mailed for some reason if I leave the Carbon Copy CC empty, so feel free to help with that also. THANKS!): Here's My Bad Code: <?php foreach ($_POST as $key => $value){ $emailtext .= $key . " = " .$value ."\n\n"; $EmailHeaders = "From: [email protected]" . "\r\n" . "CC:" . "\r\n" . "BCC:"; } mail("[email protected]", $_POST[TestNumber], $emailtext . "\n\n" . $req, $EmailHeaders); //Sends Email To Customer if ( $_POST[Variable1] == "sendEmail" OR $_POST[Variable2] == "sendEmail" OR $_POST[Variable3] == "sendEmail") { $CustTO = "$_POST[customer_name] <$_POST[customer_email]>" ; $CustCC = ""; $CustCC = "[email protected]"; $CustSubject = "Here is Your Email!"; $CustBody = " <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'> <HTML> <HEAD> <META content='text/html; charset=iso-8859-1' http-equiv=Content-Type> </HEAD> <BODY> <DIV><IMG style='WIDTH: 750px; HEIGHT: 90px' border=0 hspace=0 alt='My Logo' align=textTop src='http://MyDomain.com/folder/banner.jpg'></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial>$_POST[first_name],</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Thank you for your visit!</STRONG></FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial>You can instantly view your link(s) below:</FONT></DIV><BR> //Here is the part that does not work like I'd expect it to: <?php if ( $_POST[Variable1] == 'SendEmail') echo {<DIV><FONT size=2 face=Helvetica, Arial><STRONG>$_POST[LinkName]:</STRONG></FONT><BR> <FONT size=2 face=Helvetica, Arial><A href=http://www.MyDomain.com/links/$_POST[linknumber1].pdf>http://www.MyDomain.com/links/$_POST[linknumber1].php[/url]</FONT></DIV><BR>;} ?> //I think everything else is fine from here down: <DIV><FONT size=2 face=Helvetica, Arial><STRONG>$_POST[LastLink]:</STRONG></FONT><BR> <FONT size=2 face=Helvetica, Arial><A href=http://www.MyDomain.com/downloads/$_POST[lastlink].pdf>http://www.MyDomain.com/links/$_POST[lastLink].php[/url]</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Note: </STRONG>You will need Adobe Acrobat Reader to view/print instant download products. If you don't already have this program, you can install a free copy here:</FONT><BR> <FONT size=2 face=Helvetica, Arial><A href='http://get.adobe.com/reader/'>http://get.adobe.com/reader/[/url]</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Thanks again for visiting our site!</STRONG></FONT></DIV><BR> <DIV><IMG border=0 hspace=0 alt='My Logo' align=baseline src='http://MyDomain.com/logo.jpg'></DIV> </BODY> </HTML> "; $CustFrom = "My Name <[email protected]>"; $CustHeaders = "From:$CustFrom" . "\r\n" . "BCC:[email protected]"; $CustHeaders .= "MIME-Version: 1.0" . "\r\n"; $CustHeaders .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; mail($CustTO,$CustSubject,$CustBody,$CustHeaders); } else { } ?> Link to comment https://forums.phpfreaks.com/topic/196631-including-php-script-within-a-php-mail-function/ Share on other sites More sharing options...
peter_anderson Posted March 26, 2010 Share Posted March 26, 2010 Use the code tags, please. Untested, but have a try with this <?php foreach ($_POST as $key => $value){ $emailtext .= $key . " = " .$value ."\n\n"; $EmailHeaders = "From: [email protected]" . "\r\n" . "CC:" . "\r\n" . "BCC:"; } mail("[email protected]", $_POST[TestNumber], $emailtext . "\n\n" . $req, $EmailHeaders); //Sends Email To Customer if ( $_POST['Variable1'] == "sendEmail" OR $_POST['Variable2'] == "sendEmail" OR $_POST['Variable3'] == "sendEmail") { $CustTO = "$_POST['customer_name'] <$_POST['customer_email']>" ; $CustCC = ""; $CustCC = "[email protected]"; $CustSubject = "Here is Your Email!"; $CustBody = " <!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 4.0 Transitional//EN'> <HTML> <HEAD> <META content='text/html; charset=iso-8859-1' http-equiv=Content-Type> </HEAD> <BODY> <DIV><IMG style='WIDTH: 750px; HEIGHT: 90px' border=0 hspace=0 alt='My Logo' align=textTop src='http://MyDomain.com/folder/banner.jpg'></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial>$_POST[first_name],</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Thank you for your visit!</STRONG></FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial>You can instantly view your link(s) below:</FONT></DIV><BR>"; //Here is the part that does not work like I'd expect it to: if($_POST['Variable1'] == 'SendEmail'){ $CustBody .= '<DIV><FONT size=2 face=Helvetica, Arial><STRONG>'.$_POST['LinkName'].':</STRONG></FONT><BR> <FONT size=2 face=Helvetica, Arial><A href=http://www.MyDomain.com/links/'.$_POST['linknumber1'].'.pdf>http://www.MyDomain.com/links/'.$_POST['linknumber1'].'.php</a></FONT></DIV><BR>'; } //I think everything else is fine from here down: $CustBody .= '<DIV><FONT size=2 face=Helvetica, Arial><STRONG>'.$_POST['LastLink'].':</STRONG></FONT><BR> <FONT size=2 face=Helvetica, Arial><A href=http://www.MyDomain.com/downloads/'.$_POST['lastlink'].'.pdf>http://www.MyDomain.com/links/$_POST[lastLink].php[/url]</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Note: </STRONG>You will need Adobe Acrobat Reader to view/print instant download products. If you don't already have this program, you can install a free copy here:</FONT><BR> <FONT size=2 face=Helvetica, Arial><A href='http://get.adobe.com/reader/'>http://get.adobe.com/reader/[/url]</FONT></DIV><BR> <DIV><FONT size=2 face=Helvetica, Arial><STRONG>Thanks again for visiting our site!</STRONG></FONT></DIV><BR> <DIV><IMG border=0 hspace=0 alt='My Logo' align=baseline src='http://MyDomain.com/logo.jpg'></DIV> </BODY> </HTML>'; $CustFrom = "My Name <[email protected]>"; $CustHeaders = "From:$CustFrom" . "\r\n" . "BCC:[email protected]"; $CustHeaders .= "MIME-Version: 1.0" . "\r\n"; $CustHeaders .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; mail($CustTO,$CustSubject,$CustBody,$CustHeaders); } else { } ?> Link to comment https://forums.phpfreaks.com/topic/196631-including-php-script-within-a-php-mail-function/#findComment-1032381 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.