dwest Posted April 25, 2007 Share Posted April 25, 2007 I have this code: $pdfu_subject = $_POST['pdfu_subject']; $pdfu_send_to = $_POST['pdfu_send_to']; $pdfu_support_email = $_POST['pdfu_support_email']; $pdfu_msg = $_POST['pdfu_msg']; $pdfu_msg = stripslashes($pdfu_msg); $pdfu_headers = 'MIME-Version: 1.0'."\r\n". 'Content-type: text/html; charset=iso-8859-1'."\r\n".'From: '. $pdfu_support_email."\r\n".'Reply-To: '.$pdfu_support_email. "\r\n".'BCC: '.$pdfu_support_email."\r\n".'X-Mailer: PHP/' . phpversion(); mail($pdfu_send_to, $pdfu_subject, $pdfu_msg, $pdfu_headers); echo 'The notification was sent successfully.'; In the form that feeds this I have a textbox where the recipient is entered. If I enter a recipient, a comma, and another recipient, when I submit the form the mail is not processed. If I enter a single recipient, all is well. I need to be able to enter multiple recipients in the text box. I've tried comma, comma +space, etc. to no avail. Can someone tell me what I'm doing wrong? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/ Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 This should work for you... this will separate by commas and remove whitespace from before and after each address $pdfu_send_to = explode(",", $_POST['pdfu_send_to']); $pdfu_subject = $_POST['pdfu_subject']; $pdfu_support_email = $_POST['pdfu_support_email']; $pdfu_msg = $_POST['pdfu_msg']; $pdfu_msg = stripslashes($pdfu_msg); $pdfu_headers = 'MIME-Version: 1.0'."\r\n". 'Content-type: text/html; charset=iso-8859-1'."\r\n".'From: '. $pdfu_support_email."\r\n".'Reply-To: '.$pdfu_support_email. "\r\n".'BCC: '.$pdfu_support_email."\r\n".'X-Mailer: PHP/' . phpversion(); foreach($pdfu_send_to as $var => $val){ $pdfu_send_to = ltrim(rtrim($val)); mail($pdfu_send_to, $pdfu_subject, $pdfu_msg, $pdfu_headers); } Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237668 Share on other sites More sharing options...
dwest Posted April 25, 2007 Author Share Posted April 25, 2007 Thanks for the reply! Unfortunately is still isn't working and won't even work with a single sent to address now. Most likely, I've got something incorrect in the copy paste process. Here is what I have: $pdfu_send_to = explode(",", $_POST['pdfu_send_to']); $pdfu_subject = $_POST['pdfu_subject']; $pdfu_support_email = $_POST['pdfu_support_email']; $pdfu_msg = $_POST['pdfu_msg']; $pdfu_msg = stripslashes($pdfu_msg); $pdfu_headers = 'MIME-Version: 1.0'."\r\n". 'Content-type: text/html; charset=iso-8859-1'."\r\n".'From: '. $pdfu_support_email."\r\n".'Reply-To: '.$pdfu_support_email. "\r\n".'BCC: '.$pdfu_support_email."\r\n".'X-Mailer: PHP/' . phpversion(); foreach($pdfu_send_to as $var => $val){ $pdfu_send_to = ltrim(rtrim($val)); mail($pdfu_send_to, $pdfu_subject, $pdfu_msg, $pdfu_headers); } echo 'The notification was sent successfully.'; If you don't see anything obvious, tell me what to do to get the error to echo and I'll post the error. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237736 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 error_reporting(E_ALL); $addresses = $_POST['pdfu_send_to']; $pdfu_send_to = explode(',', $addresses); $pdfu_subject = $_POST['pdfu_subject']; $pdfu_support_email = $_POST['pdfu_support_email']; $pdfu_msg = $_POST['pdfu_msg']; $pdfu_msg = stripslashes($pdfu_msg); $pdfu_headers = 'MIME-Version: 1.0'."\r\n". 'Content-type: text/html; charset=iso-8859-1'."\r\n".'From: '. $pdfu_support_email."\r\n".'Reply-To: '.$pdfu_support_email. "\r\n".'BCC: '.$pdfu_support_email."\r\n".'X-Mailer: PHP/' . phpversion(); foreach($pdfu_send_to as $var => $val){ $address = ltrim(rtrim($val)); if(mail($address, $pdfu_subject, $pdfu_msg, $pdfu_headers)){ echo "Mail to $address successful.<br/>"; } } echo 'The notification was sent successfully.'; see if that works.. Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237744 Share on other sites More sharing options...
dwest Posted April 25, 2007 Author Share Posted April 25, 2007 That seems to work! Thanks! However, now my email address validator throws an error because there are oddities in the text box for the recipient. Here is the validator code: function is_valid_email_address($email) { $qtext = '[^\\x0d\\x22\\x5c\\x80-\\xff]'; $dtext = '[^\\x0d\\x5b-\\x5d\\x80-\\xff]'; $atom = '[^\\x00-\\x20\\x22\\x28\\x29\\x2c\\x2e\\x3a-\\x3c'. '\\x3e\\x40\\x5b-\\x5d\\x7f-\\xff]+'; $quoted_pair = '\\x5c[\\x00-\\x7f]'; $domain_literal = "\\x5b($dtext|$quoted_pair)*\\x5d"; $quoted_string = "\\x22($qtext|$quoted_pair)*\\x22"; $domain_ref = $atom; $sub_domain = "($domain_ref|$domain_literal)"; $word = "($atom|$quoted_string)"; $domain = "$sub_domain(\\x2e$sub_domain)*"; $local_part = "$word(\\x2e$word)*"; $addr_spec = "$local_part\\x40$domain"; return preg_match("!^$addr_spec$!", $email) ? 1 : 0; } Can something be adjusted to allow for the multiple addresses in the text box? Thanks so much for your help on this! Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237755 Share on other sites More sharing options...
benjaminbeazy Posted April 25, 2007 Share Posted April 25, 2007 just run your validator inside a foreach loop, after exploding the variable just like i did if the validation is before the mail, which it obviously is, then put this $addresses = $_POST['pdfu_send_to']; $pdfu_send_to = explode(',', $addresses); before the validator function and run the validator inside the loop Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237760 Share on other sites More sharing options...
dwest Posted April 25, 2007 Author Share Posted April 25, 2007 Ah! OK great. Thanks! It's been months since I've touched any PHP and I was a beginner then Thanks much for your help! Quote Link to comment https://forums.phpfreaks.com/topic/48544-solved-mail-question-regarding-multiple-recipients/#findComment-237766 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.