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 Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/ Share on other sites More sharing options...
trq Posted June 17, 2008 Share Posted June 17, 2008 if (empty($age)) { $message = "No age submitted"; } Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/#findComment-567668 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 "; Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/#findComment-567677 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; } Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/#findComment-567680 Share on other sites More sharing options...
Andrew R Posted June 17, 2008 Author Share Posted June 17, 2008 Thank you very much Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/#findComment-567696 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. Link to comment https://forums.phpfreaks.com/topic/110650-ifelse-statments-inside-php-mail/#findComment-567713 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.