Reputation: 25
I have a problem with my php mailer function when I use more than one address. Here is the code that I use:
$message = $_POST['txtMesssage'];
$mail->SetFrom('[email protected]');
$mail->AddCC('[email protected]');
$mail->AddReplyTo("[email protected]");
$mail->Subject = $_POST['txtSubject'];
$mail->Body = $message;
$mail->IsHTML(true);
$address = $_POST['txtTO'];
$mail->AddAddress($address);
where text TO is like:
[email protected],[email protected],[email protected], [email protected], [email protected],[email protected],[email protected]
Any idea, how I can make it work? Thanks
EDIT:
That works for me:
$addresses = explode(',', $_POST['txtTO']);
foreach ($addresses as $address) {
$mail->AddAddress($address);
}
Thanks!
Upvotes: 1
Views: 4507
Reputation: 3868
$addresses = explode(',', $_POST['txtTO'];);
foreach ($addresses as $address) {
$mail->AddAddress($address);
}
Upvotes: 1
Reputation: 1733
Try using array concepts, get all the form value i mean the to address in an array iterate and send it. This is like sending separate mail to recipients automated by a for loop .
$Address = array();
$Address[] = $_POST['txtTO'];
foreach($Address AS $Add=>$ToEmail){
mail($ToEmail, $Subject, $Message, $mailheaders);
Upvotes: 0