davidcriniti Posted October 19, 2011 Share Posted October 19, 2011 Hi, I've got a breakfast order form on a page on my site. On the confirmation page it lists only the items that have been ordered, and their prices. However, the same page sends a confirmation email and I'm unable to use the same if statements in the body of the email. Currently, I have to list all items. How can I incorporate if / else statements in the body of the email? $to = "$emailaddress\n"; $subject = "C2K Breakfast Order"; $headers = "From: $emailaddress\n"; $message = "<html> <body>Thanks for placing your order on the C2K breakfast page $firstname.\n <h1>Your breakfast id is: $id</h1> <strong>French toast:</strong> $french_toast<br/> <strong>Bacon, eggs and tomato on toast:</strong> $bacon_eggs_tom_toast<br/> <strong>Sausages, eggs and tomato on toast:</strong> $sausage_eggs_tom_toast<br/> <strong>Bacon and egg roll:</strong> $bacon_egg_roll<br/> <strong>Big breakfast:</strong> $big_breakfast<br/> <strong>Pancakes, ice cream and maple sauce:</strong> $pancakes<br/> <strong>Raisin toast:</strong> $raisin_toast<br/> <strong>Cinnamon toast:</strong> $cinnamon_toast<br/> <strong>Cereal and fruit:</strong> $cereal<br/> <strong>Total:</strong> $$total<br/> <strong>Your comments:</strong> $comments<br/> </body> </html> "; // Always set content-type when sending HTML email $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; if (preg_match(' /[\r\n,;\'"]/ ', $_POST['emailaddress'])) { exit('Invalid Email Address'); } else { mail($to,$subject,$message,$headers); } I basically want to say something along the lines of if ( $french_toast=="Yes" ) echo "<strong>French toast:</strong> $french_toast<br/>"; Any advice? Link to comment https://forums.phpfreaks.com/topic/249414-if-statements-in-html-email/ Share on other sites More sharing options...
requinix Posted October 19, 2011 Share Posted October 19, 2011 The simplest solution would be $message = " Thanks for placing your order on the C2K breakfast page $firstname.\n Your breakfast id is: $id "; if ($french_toast == "Yes") $message .= "French toast "; // etc. $message .= " Total: \$$total Your comments: $comments "; Link to comment https://forums.phpfreaks.com/topic/249414-if-statements-in-html-email/#findComment-1280621 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.