找到你要的答案

Q:phpmailer not sending email to gmail,yahoo,hotmail or these are blocking email sent by phpmailer

Q:phpmailer不发送邮件到Gmail,雅虎,Hotmail或这些阻塞发送phpmailer邮件

i am using PHPmailer to send emails

here is code that i have used:

        $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(); 

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 ?

我用PHPmailer发送电子邮件

这里是我使用过的代码:

        $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(); 

如果我从雅虎Gmail和Hotmail电子邮件地址发送电子邮件,还不。

我检查了跟踪错误,但没有错误。

谁能解释什么是问题?

answer1: 回答1:

Try this :

$mail = new PHPMailer(true);      // the true param means it will throw exceptions on errors, which we need to catch

        $mail->IsSMTP();            // telling the class to use SMTP
        try {
            $mail->AddAddress($to['email'],$to['name']);
            $mail->FromName = '';

            $mail->Subject = $subject;
            $mail->MsgHTML($message);


            $send = true;
            return $mail->Send();

        } catch (phpmailerException $e) {
        echo    $e->errorMessage(); //Pretty error messages from PHPMailer
        } catch (Exception $e) {
            $e->getMessage(); //Boring error messages from anything else!
        }

It will help you if any exception error.

试试这个:

$mail = new PHPMailer(true);      // the true param means it will throw exceptions on errors, which we need to catch

        $mail->IsSMTP();            // telling the class to use SMTP
        try {
            $mail->AddAddress($to['email'],$to['name']);
            $mail->FromName = '';

            $mail->Subject = $subject;
            $mail->MsgHTML($message);


            $send = true;
            return $mail->Send();

        } catch (phpmailerException $e) {
        echo    $e->errorMessage(); //Pretty error messages from PHPMailer
        } catch (Exception $e) {
            $e->getMessage(); //Boring error messages from anything else!
        }

它会帮助你,如果任何异常错误。

answer2: 回答2:

PHPMailer is only involved in submitting the message to your own mail server, and you're not having any problem there. After that, your mail server takes on the responsibility of sending it on, so you will find the answer in your mail server's logs.

There is no simple way to ensure messages end up in the inbox and not spam - if there was, spammers would be using it and filtering would be useless. Make sure your DNS resolves backwards and forwards, that you have valid SPF records, that you sign your messages with DKIM (especially important for Yahoo) and most importantly, that you don't send messages that your recipients think are spam.

phpmailer只参与提交的信息,自己的邮件服务器,和你没有任何问题。在那之后,你的邮件服务器承担发送它的责任,所以你会在你的邮件服务器日志中找到答案。

有没有简单的方法来保证消息结束在收件箱没有垃圾邮件-如果有,你会使用它和过滤是无用的。确保你的DNS解决前后,你有有效的SPF记录,您签名邮件DKIM(雅虎尤其重要),最重要的是,你不发送邮件,收件人认为是垃圾邮件。

answer3: 回答3:

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();

variable values needs to be changed accordingly. Hope these helps people having issues with PHPmailer

尝试各种方法后,我发现以下代码与几乎所有的电子邮件提供商

$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();

variable values needs to be changed accordingly. Hope these helps people having issues with PHPmailer

answer4: 回答4:

Have you looked on the post here: Using PHPMailer Results in many blocked emails? The asker solved the issue by changing the email subject:

Well I solved the issue; the code above was not the problem and works great.

In my subject, I used a phrase regarding "verify your account information" and that got it blocked on a few ISP's.

So the lesson is, your subject matters. I was looking at my php code and my body content before I realized this.

The content of the email and its subject can make ISPs ban it. You could try taking the content of one of your received emails from your inbox and see if that goes through.

你看这里:在许多阻止电子邮件使用phpmailer的结果吗?提问者通过改变邮件主题解决问题:

Well I solved the issue; the code above was not the problem and works great.

In my subject, I used a phrase regarding "verify your account information" and that got it blocked on a few ISP's.

So the lesson is, your subject matters. I was looking at my php code and my body content before I realized this.

本邮件及其学科的内容可以让ISP禁止。你可以试着从收件箱中接收你收到的邮件中的一个内容,看看是否可以通过。

php  email  phpmailer