Andrew R Posted June 17, 2008 Share Posted June 17, 2008 Hi there. How would I put if/else statements inside an php mail. For example how would I put the following inside the message variable? – if (empty($age)) { echo “No age submitted”; } $to = "$addy"; $subject ="Title"; $message = " "; $headers = "From: $forname <$email>"; mail($to, $subject, $message, $headers); Thank you Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 if (empty($age)) { $message = "No age submitted"; } Quote Link to comment Share on other sites More sharing options...
Andrew R Posted June 17, 2008 Author Share Posted June 17, 2008 Thanks Although what if I had this? $message = " Name: $name Email: $age Age: if (empty($age)) { echo “No age submitted”; } else { $age "; Quote Link to comment Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 Now I understand what your getting at, and no, your code won't work. Try something like.... $message = "Name: $name\nEmail: $email\n"; if (empty($age)) { $message .= "Age: No age submitted"; } else { $message .= "Age: " . $age; } Quote Link to comment Share on other sites More sharing options...
Andrew R Posted June 17, 2008 Author Share Posted June 17, 2008 Thank you very much Quote Link to comment Share on other sites More sharing options...
DarkWater Posted June 18, 2008 Share Posted June 18, 2008 Make sure you throw some newlines in there. Quote Link to comment 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.