21,886
社区成员
发帖
与我相关
我的任务
分享
try
{
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 0;
$mail->Host = "smtp.126.com"; // specify main and backup server
$mail->Port = 25;
$mail->Username = "sent@126.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = $mail->Username;
$mail->FromName = "myname";
$mail->AddAddress("receive@163.com", "toname");
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Mailer Error: ".$mail->ErrorInfo;
return false;
}
else
{
return true;
}
} catch (phpmailerException $e)
{
echo "Send mail failed: ".$e->errorMessage();
return false;
}
function SendEmail($sendmail,$title,$remark){
include "phpemail/phpemail.class.php";
$sendmail = '';//收件人 张三,李四,王二,麻子
$title='我要发邮件';
$remark='这是邮件内容';
$mailer=new PHPMailer();
$mailer->CharSet = "utf-8";
$mailer->ContentType = 'text/html';
$mailer->IsSMTP();
$mailer->SMTPDebug = 0;
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.163.com';
$mailer->Port = '465';
$mailer->Username = 'xxx';//发件人邮箱 (固定)
$mailer->Password = 'xxx';//发件人密码(固定)
$mailer->SetFrom($sendemail,$sendemail);收件人 张三,李四,王二,麻子
$mailer->AddAddress($sendmail);
$mailer->Subject =$title;
$mailer->MsgHTML($remark);
for($i = 0; $i< 10; $i++){
$mailer->send();
sleep(3);
}
}
调用:
SendEmail($sendmail,$title,$remark);
function SendEmail($address,$toname,$info)
{
try
{
$mail = new PHPMailer();
$mail->IsSMTP(); // set mailer to use SMTP
$mail->SMTPAuth = true; // turn on SMTP authentication
$mail->SMTPDebug = 0;
$mail->Host = "smtp.126.com"; // specify main and backup server
$mail->Port = 25;
$mail->Username = "sent@126.com"; // SMTP username
$mail->Password = "******"; // SMTP password
$mail->From = $mail->Username;
$mail->FromName = "myname";
$mail->AddAddress($address, $toname);
$mail->WordWrap = 50; // set word wrap to 50 characters
$mail->IsHTML(true); // set email format to HTML
$mail->Subject = "Here is the subject";
$mail->Body = $info;
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";
if(!$mail->Send())
{
echo "Mailer Error: ".$mail->ErrorInfo;
return false;
}
else
{
return true;
}
} catch (phpmailerException $e)
{
echo "Send mail failed: ".$e->errorMessage();
return false;
}
}
在另外一个文件会循环调用它进行发送:
for($i = 0; $i< 10; $i++){
//这里会获取到邮箱地址$address,收件人姓名$toname,发送的内容$info
SendEmail($address,$toname,$info);
sleep(3);
}
结果就会只有第一封发送成功,后边的都通不过验证if(!$mailer->Send()){
echo "邮件发送失败. <p>";
echo "错误原因: " . $mail->ErrorInfo;
exit; //如果这里不是退出,而是条件重入呢?
}
调试代码要有耐心!
别人只能给你一个思路,对不对,得由你验证
for($i=0; $i<10; $i++)
{
SendEmail();
sleep(20);
}
那你SendEmail()怎么定义?
如下:
function SendEmail($sendmail,$title,$remark){
include "phpemail/phpemail.class.php";
$sendmail = '';//收件人 张三,李四,王二,麻子
$title='我要发邮件';
$remark='这是邮件内容';
$mailer=new PHPMailer();
$mailer->CharSet = "utf-8";
$mailer->ContentType = 'text/html';
$mailer->IsSMTP();
$mailer->SMTPDebug = 0;
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.163.com';
$mailer->Port = '465';
$mailer->Username = 'xxx';//发件人邮箱 (固定)
$mailer->Password = 'xxx';//发件人密码(固定)
$mailer->SetFrom($sendemail,$sendemail);收件人 张三,李四,王二,麻子
$mailer->AddAddress($sendmail);
$mailer->Subject =$title;
$mailer->MsgHTML($remark);
for($i = 0; $i< 10; $i++){
$mailer->send();
sleep(3);
}
}
for($i = 0; $i< 10; $i++){
SendEmail($address);
sleep(3);
}
结果只有第一封能发出去。。。。。 $sendmail = '';//收件人 张三,李四,王二,麻子
$title='我要发邮件';
$remark='这是邮件内容';
$mailer=new PHPMailer();
$mailer->CharSet = "utf-8";
$mailer->ContentType = 'text/html';
$mailer->IsSMTP();
$mailer->SMTPDebug = 0;
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.163.com';
$mailer->Port = '465';
$mailer->Username = '';//发件人邮箱 (固定)
$mailer->Password = 'xxx';//发件人密码(固定)
$mailer->SetFrom('','');收件人 张三,李四,王二,麻子
$mailer->AddAddress($sendmail);
$mailer->Subject =$title;
$mailer->MsgHTML($remark);
<?php
set_time_limit(0);
ini_set("max_execution_time", "18000000");
include 'PHPMailer/class.phpmailer.php';
$sendmail = '';//收件人
$title='我要发邮件';
$remark='这是邮件内容';
$mailer=new PHPMailer();
$mailer->CharSet = "utf-8";
$mailer->ContentType = 'text/html';
$mailer->IsSMTP();
$mailer->SMTPDebug = 0;
$mailer->SMTPAuth = true;
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.163.com';
$mailer->Port = '465';
$mailer->Username = '';//发件人邮箱
$mailer->Password = 'xxx';//发件人密码
$mailer->SetFrom('','');
$mailer->AddAddress($sendmail);
$mailer->Subject =$title;
$mailer->MsgHTML($remark);
for($i = 0; $i< 10; $i++){
$mailer->send();
sleep(3);
}
?>