Ell20 Posted December 21, 2007 Share Posted December 21, 2007 Hi, I have set up a form on my site to invite users to the site. I have set it up so there are 3 boxes to put in 3 different email addresses at a time, however I obviously only want to send the message to all 3 if all 3 boxes have an email address in. I have tried using if and elseif to determine which $to statement to use but it dosent seem to be working. Am I doing something wrong? Cheers Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/ Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 Code please... Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420448 Share on other sites More sharing options...
Ell20 Posted December 21, 2007 Author Share Posted December 21, 2007 Sorry: if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email1'])))) { $e1 = escape_data($_POST['email1']); } else { $e1 = FALSE; echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>'; } if (!empty($email2)) { if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email2'])))) { $e2 = escape_data($_POST['email2']); } else { $e2 = FALSE; echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>'; } } if (!empty($email3)) { if (eregi ("^[[:alnum:]][a-z0-9_.-]*@[a-z0-9.-]+\.[a-z]{2,4}$", stripslashes(trim($_POST['email3'])))) { $e3 = escape_data($_POST['email3']); } else { $e3 = FALSE; echo '<p><font color="red" size="+1">Please enter a valid email address!</font></p>'; } } if ($e1) { $to = "$e1"; } elseif ($e1 && $e2) { $to = "$e1, $e2"; } elseif ($e1 && $e2 && $e3) { $to = "$e1, $e2, $e3"; } Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420449 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 one thing I noticed your if statements should be if ($e1 && $e2 && $e3) { $to = "$e1, $e2, $e3"; } elseif ($e1 && $e2) { $to = "$e1, $e2"; } elseif ($e1) { $to = "$e1"; } Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420457 Share on other sites More sharing options...
Ell20 Posted December 21, 2007 Author Share Posted December 21, 2007 Thanks but that hasnt solved it, it only ever sends one email. Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420461 Share on other sites More sharing options...
rajivgonsalves Posted December 21, 2007 Share Posted December 21, 2007 if you echo $to what do you get ? Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420465 Share on other sites More sharing options...
Ell20 Posted December 21, 2007 Author Share Posted December 21, 2007 I filled in all 3 input boxes and echoed $to and it only showed the email address posted in the first input. Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420466 Share on other sites More sharing options...
PFMaBiSmAd Posted December 21, 2007 Share Posted December 21, 2007 My guess would be that $email2 and $email3 are not set to anything by the code and if (!empty($email2)) { and if (!empty($email3)) { are false. Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420469 Share on other sites More sharing options...
Ell20 Posted December 21, 2007 Author Share Posted December 21, 2007 Ok, is there another way which you recommend I can do this? Cheers Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420473 Share on other sites More sharing options...
Ell20 Posted December 21, 2007 Author Share Posted December 21, 2007 Ive got it working now, by removing the if to check whether the input box contains anything however I somehow need to put that back in. Link to comment https://forums.phpfreaks.com/topic/82670-php-mail/#findComment-420481 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.