Home > Backend Development > PHP Tutorial > phpmailer循环发送邮件失败解决方法

phpmailer循环发送邮件失败解决方法

WBOY
Release: 2016-06-13 11:48:43
Original
1089 people have browsed it

phpmailer循环发送邮件失败

本帖最后由 an5464684 于 2013-12-27 18:20:21 编辑 使用的是phpmailer,账户和密码均正确,并测试通过。
1.单次发送会成功
2.但是当编写一个循环发邮件时,只有第一次发送成功,后面的都发送失败,查看Log显示:Could not authenticate,验证没有通过。
这是什么原因?
<br />try <br />{<br />	$mail = new PHPMailer();<br />	$mail->IsSMTP();   // set mailer to use SMTP<br />	$mail->SMTPAuth = true;     // turn on SMTP authentication	<br />	$mail->SMTPDebug  = 0;<br /><br />	$mail->Host = "smtp.126.com";  // specify main and backup server<br />	$mail->Port = 25;<br />			<br />	$mail->Username = "[email&#160;protected]";  // SMTP username<br />	$mail->Password = "******"; // SMTP password<br /><br />	$mail->From = $mail->Username;<br />	$mail->FromName = "myname";<br />	$mail->AddAddress("[email&#160;protected]", "toname");<br /><br />	$mail->WordWrap = 50;         // set word wrap to 50 characters<br />	$mail->IsHTML(true);          // set email format to HTML<br /><br />	$mail->Subject = "Here is the subject";<br />	$mail->Body    = "This is the HTML message body <b>in bold!</b>";<br />	$mail->AltBody = "This is the body in plain text for non-HTML mail clients";<br />		<br />	if(!$mail->Send())<br />	{<br />		echo "Mailer Error: ".$mail->ErrorInfo;	<br />		return false;<br />	}<br />	else <br />	{<br />		return true;<br />	}<br /><br />                       <br />} catch (phpmailerException $e) <br />{<br />	echo "Send mail failed: ".$e->errorMessage();<br />	return false;<br />}<br />
Copy after login

------解决方案--------------------
单次成功的话程序是没有问题的,因为你用的是126的邮件服务器那它肯定不会让你不间断的循环发送的,所以你可以再发送完成一封之后让程序sleep几秒钟
------解决方案--------------------
一般来说,像qq、163、126等邮箱,他们不会允许你连续发送的,所以如果你要循环发送的话,可以sleep 几秒,但每发一封邮件sleep几秒,效率肯定不高,也可以同时给多个用户发送,然后sleep几秒
------解决方案--------------------
<br /><?php<br />    set_time_limit(0);<br />    ini_set("max_execution_time", "18000000");<br />    include 'PHPMailer/class.phpmailer.php';<br />    $sendmail = '';//收件人<br />    $title='我要发邮件';<br />    $remark='这是邮件内容';<br />	$mailer=new PHPMailer();<br />	$mailer->CharSet = "utf-8";<br />	$mailer->ContentType = 'text/html';<br />	$mailer->IsSMTP();<br />	$mailer->SMTPDebug  = 0;<br />	$mailer->SMTPAuth = true;<br />	$mailer->SMTPSecure = 'ssl';<br />	$mailer->Host = 'smtp.163.com';<br />	$mailer->Port = '465';<br />	$mailer->Username = '';//发件人邮箱<br />	$mailer->Password = 'xxx';//发件人密码<br />	$mailer->SetFrom('','');<br />	$mailer->AddAddress($sendmail);<br />	$mailer->Subject =$title;<br />	$mailer->MsgHTML($remark);<br />	for($i = 0; $i< 10; $i++){<br />		$mailer->send();<br />		sleep(3);<br />    }<br />?><br />
Copy after login

我试过是没有问题的。

------解决方案--------------------
每次发送完一次,关闭一次。
查看phpmailer属性。
使用 Smtpclose();方法就可以了。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template