4

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("cpn@xxxxxxx.com");
$mail->Subject = $sub1;
$mail->Body = $text_mail;
$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");
 if(!$mail->Send()){
 echo "Mailer Error: " . $mail->ErrorInfo;
}
else{
 echo "Message has been sent";
}

any one guide me how to do it

Adarsh M Pallickal
  • 813
  • 3
  • 16
  • 37
arok
  • 1,795
  • 7
  • 27
  • 56

7 Answers7

8

Change this line

$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");

to this:

$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");

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

Community
  • 1
  • 1
Jamie Taylor
  • 4,709
  • 5
  • 44
  • 66
2

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

$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");

See PHPMailer AddAddress() for more details.

Community
  • 1
  • 1
cubitouch
  • 1,929
  • 15
  • 28
2

If you want to send email to multiple address, You need to call the AddAddress() function for each and every Email address. First parameter is EMAIL address, Second one is Recipient name and it is optional.

$mail->AddAddress("xxxxxxx@gmail.com", "XXXXXXXX");
$mail->AddAddress("aral@xxxxxx.com", "Aral");
Krish R
  • 22,583
  • 7
  • 50
  • 59
0

Try this

$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");
user1844933
  • 3,296
  • 2
  • 25
  • 42
0

Take a look here PHPMailer AddAddress()

and keep an eye of your line:

  $mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");
Community
  • 1
  • 1
donald123
  • 5,638
  • 3
  • 26
  • 23
0

Instead of:

$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");

You should use

$mail->AddAddress('xxxxxxx@gmail.com', '1');
$mail->AddAddress('aral@xxxxxx.com', '2');
$mail->AddAddress('akhader@xxxxxx.com', '3');

Or use CC copies:

$mail->AddCC('xxxxxxx@gmail.com', '1');
$mail->AddCC('aral@xxxxxx.com', '2');
$mail->AddCC('akhader@xxxxxx.com', '3');
Alex Pliutau
  • 21,392
  • 27
  • 113
  • 143
0

Try this.... This may help you

<html>
<body>

  <?php
  if (isset($_REQUEST['email']))
 //if "email" is filled out, send email
 {
 //send email
 $email = $_REQUEST['email'] ;
 $subject = $_REQUEST['subject'] ;
 $message = $_REQUEST['message'] ;
      mail("chauhanamrish32@gmail.com,amrinderpuri1990@gmail.com,amrinder_puri@yahoo.com,amrindersinghpuri13@gmail.com", $subject,$message, "From:" . $email);
  echo "Thank you for using our mail form";
  }
  else
//if "email" is not filled out, display the form
{
echo "<form method='post' action='mail.php'>
Email: <input name='email' type='text'><br>
Subject: <input name='subject' type='text'><br>
Message:<br>
<textarea name='message' rows='15' cols='40'>
</textarea><br>
<input type='submit'>
 </form>";
  }
?>

Amrinder Singh
  • 5,300
  • 12
  • 46
  • 88