Reputation: 1845
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
Upvotes: 5
Views: 6178
Reputation: 22741
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("[email protected]", "XXXXXXXX");
$mail->AddAddress("[email protected]", "Aral");
Upvotes: 2
Reputation: 5532
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("[email protected],[email protected],[email protected],[email protected]", $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>";
}
?>
Upvotes: 0
Reputation: 21947
Instead of:
$mail->AddAddress("[email protected];[email protected];[email protected]");
You should use
$mail->AddAddress('[email protected]', '1');
$mail->AddAddress('[email protected]', '2');
$mail->AddAddress('[email protected]', '3');
Or use CC copies:
$mail->AddCC('[email protected]', '1');
$mail->AddCC('[email protected]', '2');
$mail->AddCC('[email protected]', '3');
Upvotes: 0
Reputation: 5749
Take a look here PHPMailer AddAddress()
and keep an eye of your line:
$mail->AddAddress("[email protected];[email protected];[email protected]");
Upvotes: 0
Reputation: 3427
Try this
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
$mail->AddAddress("[email protected]");
Upvotes: 0
Reputation: 4775
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.
Upvotes: 8
Reputation: 1937
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.
Upvotes: 2