I need to send the email to the multiple recipients but I am getting error in my code. I need to send the email to multiple recipients.
<?php
require 'phpmailer/PHPMailerAutoload.php';
if(isset($_POST['send']))
{
$email = $_POST['email'];
$password = $_POST['password'];
$to_id = $_POST['toid'];
$message = $_POST['message'];
$subject = $_POST['subject'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'mail.domain.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = $email;
$mail->Password = $password;
$mail->setFrom('info@domain.com', 'name');
$mail->addReplyTo('info@domain.com', 'name');
$mail->addAddress($to_id);
$mail->Subject = $subject;
$mail->msgHTML($message);
if(!$mail->send()) {
$error = "Mailer Error: " . $mail->ErrorInfo;
?>
<script>alert('<?php echo $error ?>');</script>
<?php
}
else {
echo "Message Sent Successfully";
}
}
?>
Try this code.
instead of
$mail->addAddress($to_id);
use something like this:You can use just like that:
Or if you have emails in an array
$_POST['toid']
, than you can useAddAddress()
in a loop.