Gainax Posted July 22, 2009 Share Posted July 22, 2009 Hi I have a form which sends out an email. I'm trying to send it to muliple people. The following is my code: $to = "bob@example.com"; $subject = "New Applicants submit"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; /* headers adicionais */ $headers .= "To: Jim <jim@example.com>, Ted <ted@example.com>\r\n"; $headers .= "From: Web <website@example.com>\r\n"; mail($to, $subject, $msg, $headers); This all works fine when I put the email addresses of some of my colleagues (using Gmail). But If I try putting any other email, those who use Outlook, no-one receives the emails. Is there anything wrong with my form? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/ Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 You need to add the additional recipients to the $to section adding them to the headers is not enough that just notifies the others as to who the email was sent. Also if it works on a gmail account then it is fine, sounds like you have the wrong emails or the outlook users do not have there email client setup right, or it is filtering it as spam, be sure to check junk folder in outlook. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880375 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 $to = "bob@example.com, ted@example.com, jim@example.com"; Will this do? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880387 Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 $to = "bob@example.com, ted@example.com, jim@example.com"; Will this do? Yes. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880394 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 $to = "bob@example.com, ted@example.com, jim@example.com"; Will this do? Yes. Their has been a post before who had problems sending his mail to multiple recipients using $to. Altough 'to' can accept multiple recipients it's probably better - for spam sake's - to only add 1 'to' recipient and split all others over cc and bcc Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880407 Share on other sites More sharing options...
jcrew Posted July 22, 2009 Share Posted July 22, 2009 $to = "bob@example.com, ted@example.com, jim@example.com"; Will this do? Yes. Their has been a post before who had problems sending his mail to multiple recipients using $to. Altough 'to' can accept multiple recipients it's probably better - for spam sake's - to only add 1 'to' recipient and split all others over cc and bcc That's interesting! Definitely keeping that in mind. (Usually, in the far few in between cases where I use mail(), I just hold a while() statement and send each person an individual email). Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880411 Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 I concur with Jcrew, as it has been my experince that if I have more than 3 recipients then the messages need to be sent as seperate emails. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880421 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 So something along the lines of: $to = "bob@example.com"; $subject = "New Applicants submit"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; /* headers adicionais */ $headers .= "From: Web <website@example.com>\r\n"; $headers . = "Cc: jim <jim@example.com>, ted <ted@example.com>"; mail($to, $subject, $msg, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880427 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 I concur with Jcrew, as it has been my experince that if I have more than 3 recipients then the messages need to be sent as seperate emails. How would I do this? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880431 Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 <?php $to=explode(',',$to); foreach($to as $recipient) { mail($recipient,$subject,$message); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880434 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 Will I still have the following code? $to = "bob@example.com, ted@example.com, jim@example.com"; Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880437 Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 Yes but you should use single quotes instead of double, just because double are not necessary and add some extra processing time. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880439 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 What about the headers? The email gets sent as HTML. Can I still have the $headers in the mail()? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880444 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 My code is : $to = 'jim@example.com, bob@example.com, ted@example.com'; $subject = "New Applicants submit"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "To: Ted <ted@example.com>, bob <bob@example.com>, jim <jim@example.com>\r\n"; $headers .= "From: Website <website@example.com>\r\n"; $to = explode(',',$to); foreach($to as $recipient) { mail($recipient,$subject,$msg,$headers); } Should this work? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880464 Share on other sites More sharing options...
WolfRage Posted July 22, 2009 Share Posted July 22, 2009 Yes but you should also get rid of the space between recipients on the $to var. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880478 Share on other sites More sharing options...
Gainax Posted July 22, 2009 Author Share Posted July 22, 2009 Ok thanks. I'll see If those who should get the emails do in fact get them Thanks Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880488 Share on other sites More sharing options...
ignace Posted July 22, 2009 Share Posted July 22, 2009 I concur with Jcrew, as it has been my experince that if I have more than 3 recipients then the messages need to be sent as seperate emails. Possibly even personalising the e-mail. Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-880624 Share on other sites More sharing options...
Gainax Posted July 23, 2009 Author Share Posted July 23, 2009 Ok I have the following code now, and only I can get the emails: $to = 'client1@example.co.uk,client2@example.co.uk,me@example.com'; $subject = "Form Submit"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "To: Client1 <client1@example.co.uk>,Client2 <client2@example.co.uk>,Me <me@example.com>\r\n"; $headers .= "From: Website <website@example.co.uk>\r\n"; $to = explode(',',$to); foreach($to as $recipient) { if (mail($recipient, $subject, $message, $headers)) { header('Location: thankyou.php'); } else { echo("<p>Message delivery failed...</p>"); } } I get the emails fine. But the other 2 email addresses don not receive anything. Is there anything wrong with my code? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-881041 Share on other sites More sharing options...
ignace Posted July 23, 2009 Share Posted July 23, 2009 Ok I have the following code now, and only I can get the emails: $to = 'client1@example.co.uk,client2@example.co.uk,me@example.com'; $subject = "Form Submit"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers .= "To: Client1 <client1@example.co.uk>,Client2 <client2@example.co.uk>,Me <me@example.com>\r\n"; $headers .= "From: Website <website@example.co.uk>\r\n"; $to = explode(',',$to); foreach($to as $recipient) { if (mail($recipient, $subject, $message, $headers)) { header('Location: thankyou.php'); } else { echo("<p>Message delivery failed...</p>"); } } I get the emails fine. But the other 2 email addresses don not receive anything. Is there anything wrong with my code? Thanks There is nothing wrong with your code. It's probably the SPAM filters that stop your e-mail from being received either send each e-mail individually or only add one $to and add the others to $cc or $bcc Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-881050 Share on other sites More sharing options...
Gainax Posted July 23, 2009 Author Share Posted July 23, 2009 Ok I now have this: $to = 'me@example.com'; $subject = "Form Submit"; $headers .= "From: Website <me@example.com>\r\n"; $headers .= "To: me2@example.com\r\n"; $headers .= "Cc: clients1@example.co.uk\r\n"; $headers .= "Bcc: client2@example.com\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"; if (mail($to, $subject, $message, $headers)) { header('Location: thankyou.php'); } else { echo("<p>Message delivery failed...</p>"); } Does this look ok? Quote Link to comment https://forums.phpfreaks.com/topic/166982-php-form-not-receiving-email/#findComment-881061 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.