[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
在上一篇([PHP] 線上發信如何通過驗證的SMTP(使用PHPMailer)) 中我們討論到如何使用 PHPMailer 類別來通過驗證的伺服器,其實如果您下載了PHPMailer並解開壓縮後,可以在<examples>資料夾中看到各個不同狀況下使用 PHPMailer 來發信的程式碼,其中<test_gmail.php>就是使用 PHPMailer透過Gmail的範例。
茶米整理一下在這裡分享給大家:
一般來說這樣即可完成使用 Gmail 發信的動作了,茶米在實作中有幾個要注意的事項敘述如下:
- 其中要注意的是Gmail 的 SMTP主機固定位址是 smtp.gmail.com,必須使用 465 埠以 SSL 的方式來連線。
- 有許多朋友可能在測試時還是無法正確連線,根據茶米的經驗要檢查的地方,是若要使用 SSL 的方式進行連線,PHP 必須安裝 OpenSSL 的擴充程式,如此才能正確連線並使用 Gmail 執行寄信的動作。
分享給您使用。
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
經過我研究了五個小時!
最好使用php 5以上
因為php 4 ,有OpenSSL的bug…
然後phpmailer 使用2.1 以上版本for php 5/6
就一次就成功了
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
請問各位大大,我也是用這個來做
但我顯示
Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in E:\AppServ\www\star\phpmailer\class.smtp.php on line 122
Mailer : 錯誤SMTP Error: Could not connect to SMTP host.
請問有人可以幫我解答嗎@@?
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
看這裡的說明:http://tw.php.net/manual/en/transports.inet.php
The ssl:// and tls:// transports (available only when openssl support is compiled into PHP) are extensions of the tcp:// transport which include SSL encryption. Since PHP 4.3.0 OpenSSL support must be statically compiled into PHP, since PHP 5.0.0 it may be compiled as a module or statically.
ssl:// will attempt to negotiate an SSL V2, or SSL V3 connection depending on the capabilities and preferences of the remote host. sslv2:// and sslv3:// will select the SSL V2 or SSL V3 protocol explicitly.
確認你的PHP版本及php.ini的設定,以知道你的fsockopen是否可以使用ssl的協定!
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
不好意思,我也遇到相關問題。
Warning: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.gmail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?) in C:\AppServ\www\LibrarySystem\class.smtp.php on line 122
我是PHP5,官網上的每個版本我都下載過了。還是會出現這種情況...
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)

系統管理員
茶米與樓上一些網友不是說過了嗎:「PHP 必須安裝 OpenSSL 的擴充程式」,您沒有確認 PHP 中的 OpenSSL 是否打開,你下載多新的版本都沒有用啊!
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)

一般會員
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
請問這個有 密件副本 嗎?
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)

一般會員
//設定密件副本
$mail->AddBCC("EMAIL位址");
Re:[PHP] 如何利用 Gmail 的SMTP 發信(使用PHPMailer)
一般會員
系統管理員