bbizzl Posted November 8, 2011 Share Posted November 8, 2011 Hello! Currently I have a form where the user can submit emails in a comma separated format to the $row in database $contacts. How can I set this up correctly so the user can email their contacts? As of right now the script emails everybody but just not in the correct email format. Thank You! The problem is when the emails are sent out; multiple email addresses are in the "to field" of the recipients email. Example if there are 5 email addresses saved in the user row $contacts; 5 email addresses show in each of the recipients to field of their email. The problem is when the emails are sent out; multiple email addresses are in the "to field" of the recipients email. Example if there are 5 email addresses saved in the user row $contacts; 5 email addresses show in each of the recipients to field of their email. <?php $formMessage = ""; $senderName = ""; $senderEmail = ""; $senderMessage = ""; if (isset($_POST['cusername'])) { $senderName = $_POST['cusername']; $senderEmail = $_POST['cemail']; $senderMessage = $_POST['msg']; if (!$senderName || !$senderEmail ) { $formMessage = "The form is incomplete, please fill in all fields."; } else { $senderName = strip_tags($senderName); $senderName = stripslashes($senderName); $senderEmail = strip_tags($senderEmail); $senderEmail = stripslashes($senderEmail); $senderMessage = strip_tags($senderMessage); $senderMessage = stripslashes($senderMessage); $to = $contacts; $from = ""; $subject = "Prospect For Property"; $message = '<html><body>'; $message .= "</body></html>"; $headers = "MIME-Version: 1.0\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; mail($to, $subject, $message, $headers); $formMessage = "Thanks, your message has been sent."; $senderName = ""; $senderEmail = ""; $senderMessage = ""; } } ?> MOD EDIT: PHP Manual link [m] . . . [/m] tags changed to . . . tags . . . Quote Link to comment https://forums.phpfreaks.com/topic/250711-php-email-row-from-mysql/ Share on other sites More sharing options...
fever84 Posted February 4, 2012 Share Posted February 4, 2012 Hi, is $contacts an array ? if its not explode it. for example $strContacts = "name@domain.com, name@domain.com, name@domain.com"; $arrContacts = explode(", " $strContacts); Then once all of your contacts are in an array loop round them sending the emails $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n"; foreach ($arrContacts as $strContact) { mail($strContact, $subject, $message, $headers); } $formMessage = "Thanks, your message has been sent."; $senderName = ""; $senderEmail = ""; $senderMessage = ""; Quote Link to comment https://forums.phpfreaks.com/topic/250711-php-email-row-from-mysql/#findComment-1314456 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.