-1

I'm trying to get this to send the form information to multiple e-mails but for some reason it only sends to whichever e-mail is listed first in the $mail->address field. Can anyone help?

if(empty($errors)) {

        require 'phpmailer/PHPMailerAutoload.php';

        $mail = new PHPMailer;

        $mail->isSMTP();
        $mail->Host = '192.168.555.555';
        $mail->SMTPAuth = false;
        $mail->Username = '';
        $mail->Password = '';
        $mail->SMTPSecure = '';
        $mail->Port = 25;
        $mail->From = 'donotreply@website.com';
        $mail->FromName = $from;
        $mail->addAddress('email1@email.com' , 'email2@email.com');
        $mail->isHTML(true);
        $mail->Subject = 'Employment Application';
        $mail->Body    = $message;

        if($mail->send()) {
            //echo 'Mailer Error: ' . $mail->ErrorInfo;
            $success = '<div class="alert alert-success"><h3 style="margin:0">Message Sent!</h3></div>';
        }

    }
thefuzz
  • 3
  • 1

2 Answers2

2

The addAddress() method only accept one email address and the name of the recipient that is optional. You can add multiple addAddress() method to send the same message to multiple email address like the following:

$mail->addAddress('joe@example.net', 'Joe User');
$mail->addAddress('john@example.com', 'John Doe');

Alternatively, a better way would be to send carbon copy. You can send the carbon copy by using the following method:

$mail->addCC('cc@example.com');

If you like you can also use BCC:

$mail->addBCC('bcc@example.com');
Md Mazedul Islam Khan
  • 5,318
  • 4
  • 40
  • 66
0

The method addAddress accepts one email address at a time. The second parameter is optional.

public function addAddress($address, $name = '')
{
    return $this->addAnAddress('to', $address, $name);
}
mjcriswell
  • 21
  • 4