phpmailer透過gmail發信?

WBOY
Lepaskan: 2023-03-01 19:08:01
asal
1780 orang telah melayarinya

請問如何透過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>
Salin selepas log masuk
Salin selepas log masuk

跳出的錯誤

<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>
Salin selepas log masuk
Salin selepas log masuk

確定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>
Salin selepas log masuk
Salin selepas log masuk

跳出的錯誤

<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>
Salin selepas log masuk
Salin selepas log masuk

確定gmail帳號密碼沒錯呀


看來確實bluehost不能用gmail

提示连接超时啊,主机哪的啊,可以访问google服务么?

先用你的代码在本地测试,看是否有问题,如果没问题再咨询虚拟主机供应商。

错误信息上看,很大可能是代码所在服务器的网络根本不能访问gmail邮件服务器。

<code>没连接到`$mail->Host = "smtp.gmail.com";`</code>
Salin selepas log masuk

通过smtp POP3或IMAP协议

Label berkaitan:
sumber:php.cn
Kenyataan Laman Web ini
Kandungan artikel ini disumbangkan secara sukarela oleh netizen, dan hak cipta adalah milik pengarang asal. Laman web ini tidak memikul tanggungjawab undang-undang yang sepadan. Jika anda menemui sebarang kandungan yang disyaki plagiarisme atau pelanggaran, sila hubungi admin@php.cn
Tutorial Popular
Lagi>
Muat turun terkini
Lagi>
kesan web
Kod sumber laman web
Bahan laman web
Templat hujung hadapan