我有一些PHP代码,我用它来发送电子邮件到特定的电子邮件地址。但是,我想在PHP发送它时在PHP中包含更多的电子邮件地址。 当我尝试显示以下
时错误:邮件程序错误:您必须至少提供一个收件人电子邮件地址。
码
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";
}
任何人指导我如何做到
答案 0 :(得分:7)
更改此行
$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");
到此:
$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");
您可以根据需要多次运行该功能,直到您获得所需的所有地址为止。
答案 1 :(得分:2)
您似乎错过了使用AddAdress
方法。你应该像那样分开传递每一封邮件:
$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");
有关详细信息,请参阅PHPMailer AddAddress()。
答案 2 :(得分:2)
如果您要将电子邮件发送到多个地址,则需要为每个电子邮件地址调用AddAddress()
功能。第一个参数是EMAIL address
,第二个参数是Recipient
名称,它是可选的。
$mail->AddAddress("xxxxxxx@gmail.com", "XXXXXXXX");
$mail->AddAddress("aral@xxxxxx.com", "Aral");
答案 3 :(得分:0)
试试这个
$mail->AddAddress("xxxxxxx@gmail.com");
$mail->AddAddress("aral@xxxxxx.com");
$mail->AddAddress("akhader@xxxxxx.com");
答案 4 :(得分:0)
并密切关注你的观点:
$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");
答案 5 :(得分:0)
而不是:
$mail->AddAddress("xxxxxxx@gmail.com;aral@xxxxxx.com;akhader@xxxxxx.com");
你应该使用
$mail->AddAddress('xxxxxxx@gmail.com', '1');
$mail->AddAddress('aral@xxxxxx.com', '2');
$mail->AddAddress('akhader@xxxxxx.com', '3');
或使用CC副本:
$mail->AddCC('xxxxxxx@gmail.com', '1');
$mail->AddCC('aral@xxxxxx.com', '2');
$mail->AddCC('akhader@xxxxxx.com', '3');
答案 6 :(得分:0)
试试这个....这可能对你有帮助
<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>";
}
?>