SMTP doesn't send mail to gmail and yahoo but has no error

时间:2016-08-31 17:38:50

标签: php email smtp phpmailer

I'm trying to use google SMTP. It works fine with sending mail to my domain mail address but I don't receive any mail on gmail or yahoo. I've checked ssl, ports, ... also there is no error as $mail -> send() returns true. I checked other questions but I couldn't find anything useful to my problem.

Here is my code:

require_once("./PHPMailer-5.2.16/class.phpmailer.php");
           $mail = new PHPMailer();
           $mail->IsSMTP();
           $mail->SMTPSecure = 'ssl';
           $mail->SMTPDebug = 1;
           $mail->SMTPAuth = true;
           $mail->Host = "smtp.gmail.com";
           $mail->Port = 465;
           $mail->Username = "e.g@gmail.com";
           $mail->Password = "password";
           $mail->SetFrom("e.g@gmail.ir");
           $mail->Subject = "This is just a test";
           $mail->Body = "Just a test";
           $mail->AddAddress($email);// or $mail->AddAddress("e.g@gmail.com)
           if (!$mail->Send()) {
                echo "Mailer Error." . $mail->ErrorInfo;
           }

I've also tried:

tls

ports 587 and 485

$mail->Host = "ssl://smtp.googlemail.com";

$mail->Host = "ssl://smtp.gmail.com";

but none of them worked.

-And I just figured out

"Only when I delete the line $mail->IsSMTP(); my domain mail can receive mail!"

Update: I also tried $mail->SMTPDebug = 2; but couldn't find any log/message print out.

0 个答案:

没有答案