Maison > Article > développement back-end > phpmailer透過gmail發信?
請問如何透過gmail寄信?
我是使用虛擬主機(BLUEHOST)且申請它內建的電子郵件服務,然後加上phpmailer是可以寄信的。
只是我想改成透過gmail寄信
於是就失敗了
我參考這裡:http://stackoverflow.com/ques...
<code>$mail = new PHPMailer(); $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "***@gmail.com"; $mail->Password = "***"; $mail->SetFrom("***@gmail.com"); $mail->Subject = "Test"; $mail->Body = "hello"; $mail->AddAddress("xxxxxxxx@gmail.com"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }</code>
跳出的錯誤
<code>SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: ***@gmail.com : Called Mail() without being connected Mailer Error: The following From address failed: ***@gmail.com : Called Mail() without being connected</code>
確定gmail帳號密碼沒錯呀
看來確實bluehost不能用gmail
請問如何透過gmail寄信?
我是使用虛擬主機(BLUEHOST)且申請它內建的電子郵件服務,然後加上phpmailer是可以寄信的。
只是我想改成透過gmail寄信
於是就失敗了
我參考這裡:http://stackoverflow.com/ques...
<code>$mail = new PHPMailer(); $mail->IsSMTP(); // enable SMTP $mail->SMTPDebug = 1; $mail->SMTPAuth = true; $mail->SMTPSecure = 'ssl'; $mail->Host = "smtp.gmail.com"; $mail->Port = 465; $mail->IsHTML(true); $mail->Username = "***@gmail.com"; $mail->Password = "***"; $mail->SetFrom("***@gmail.com"); $mail->Subject = "Test"; $mail->Body = "hello"; $mail->AddAddress("xxxxxxxx@gmail.com"); if(!$mail->Send()) { echo "Mailer Error: " . $mail->ErrorInfo; } else { echo "Message has been sent"; }</code>
跳出的錯誤
<code>SMTP -> ERROR: Failed to connect to server: Connection timed out (110) The following From address failed: ***@gmail.com : Called Mail() without being connected Mailer Error: The following From address failed: ***@gmail.com : Called Mail() without being connected</code>
確定gmail帳號密碼沒錯呀
看來確實bluehost不能用gmail
提示连接超时啊,主机哪的啊,可以访问google服务么?
先用你的代码在本地测试,看是否有问题,如果没问题再咨询虚拟主机供应商。
错误信息上看,很大可能是代码所在服务器的网络根本不能访问gmail邮件服务器。
<code>没连接到`$mail->Host = "smtp.gmail.com";`</code>
通过smtp POP3或IMAP协议