phpmailer不发送邮件到gmail,yahoo,hotmail或这些阻止phpmailer发送的邮件 [英] phpmailer not sending email to gmail,yahoo,hotmail or these are blocking email sent by phpmailer
本文介绍了phpmailer不发送邮件到gmail,yahoo,hotmail或这些阻止phpmailer发送的邮件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用PHPmailer发送电子邮件
i am using PHPmailer to send emails
这里是我使用的代码:
$mail = new PHPMailer();
$subject = "test";
$to = "test_patel@yahoo.com"
$mail->SetFrom("PDSociety@aol.com","Punjab Dental Society");
$mail->AddReplyTo("PDSociety@aol.com", "Punjab Dental Society");
$mail->Subject = $subject;
$mail->MsgHTML($str);
$mail->AddAddress($to, "Punjab Dental Society");
if(!$mail->Send())
{
$err = "Mailer Error: " . $mail->ErrorInfo;
//echo $err;
} else {
$msg = "Message sent!";
}
// Clear all addresses and attachments for next loop
$mail->ClearAddresses();
如果我将电子邮件地址从yahoo更改为Gmail或Hotmail,仍然发送电子邮件。
if i change email address from yahoo to gmail or hotmail, still email are not sent.
我通过回显错误检查,但没有错误。
i checked by echoing error, but no errors.
任何人都可以解释是什么问题?
can anyone explain what is the issue ?
推荐答案
在尝试各种方式后,我发现以下代码与几乎所有的电子邮件提供者一起工作
After trying various ways, i found following code working with almost all email providers
$to['email'] = "recipients email address";
$to['name'] = "name";
$subject = "email subject";
$str = "<p>Hello, World</p>";
$mail = new PHPMailer;
$mail->IsSMTP();
$mail->SMTPAuth = true;
$mail->Host = 'Specify main and backup server here';
$mail->Port = 465;
$mail->Username = 'xyz@domainname.com';
$mail->Password = 'email account password';
$mail->SMTPSecure = 'ssl';
$mail->From = 'From Email Address';
$mail->FromName = "Any Name";
$mail->AddReplyTo('xyz@domainname.com', 'any name');
$mail->AddAddress($to['email'],$to['name']);
$mail->Priority = 1;
$mail->AddCustomHeader("X-MSMail-Priority: High");
$mail->WordWrap = 50;
$mail->IsHTML(true);
$mail->Subject = $subject;
$mail->Body = $str;
if(!$mail->Send()) {
$err = 'Message could not be sent.';
$err .= 'Mailer Error: ' . $mail->ErrorInfo;
}
$mail->ClearAddresses();
变量值需要相应更改。
希望这些帮助人们遇到PHPmailer的问题
variable values needs to be changed accordingly. Hope these helps people having issues with PHPmailer
这篇关于phpmailer不发送邮件到gmail,yahoo,hotmail或这些阻止phpmailer发送的邮件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文