Jump to content

if statements in html email


davidcriniti

Recommended Posts

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
Share on other sites

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
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.