Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PHP mail send to Multiple recipients

Tags:

php

email

I have some PHP code that I'm using to send email to a specific e-mail address. However, I'd like to include a couple more e-mail addresses in the PHP for when it sends it. when i tried it showing the following

ERROR:Mailer Error: You must provide at least one recipient email address.

code

include "class.phpmailer.php"; // include the class file name
$mail = new PHPMailer(); // create a new object
$mail->IsSMTP(); // enable SMTP
$mail->SMTPDebug = 1; // debugging: 1 = errors and messages, 2 = messages only
$mail->SMTPAuth = true; // authentication enabled
//$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail
$mail->Host = "mail.authsmtp.com";
$mail->Port = "25"; // or 587
$mail->IsHTML(true);
$mail->Username = "xxxxx";
$mail->Password = "xxxxx";
$mail->SetFrom("[email protected]");
$mail->Subject = $sub1;
$mail->Body = $text_mail;
$mail->AddAddress("[email protected];[email protected];[email protected]");
 if(!$mail->Send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
 echo "Message has been sent";
}

any one guide me how to do it

like image 367
arok Avatar asked Dec 19 '22 19:12

arok


2 Answers

Change this line

$mail->AddAddress("[email protected];[email protected];[email protected]");

to this:

$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");

You can run that function as many times as you like until you've got all the addresses you need.

See Here for more info

like image 62
Jamie Taylor Avatar answered Dec 24 '22 00:12

Jamie Taylor


It seems that you are miss using the AddAdress method. You should pass every mail separatly like that :

$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");

See PHPMailer AddAddress() for more details.

like image 39
cubitouch Avatar answered Dec 24 '22 01:12

cubitouch