-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 = '[email protected]';
        $mail->FromName = $from;
        $mail->addAddress('[email protected]' , '[email protected]');
        $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('[email protected]', 'Joe User');
$mail->addAddress('[email protected]', '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('[email protected]');

If you like you can also use BCC:

$mail->addBCC('[email protected]');
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