請問如何透過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協定