預覽: 我一直在嘗試使用Moodle發送電子郵件很長一段時間,最後決定使用標準PHP郵件()函數測試郵件是否正常工作。無法使用PHP發送電子郵件
但即使PHP不發送電子郵件!
問題場景:
這是我的PHP代碼:
$to = "[email protected]";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "[email protected]";
$headers = "From:" . $from;
ini_set("sendmail_from", "[email protected]");
ini_set("SMTP", "smtp.gmail.com");
ini_set("smtp_port", "25");
ini_set("username","[email protected]");
ini_set("password","password");
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
這是我得到的錯誤是:
Warning: mail() [function.mail]: SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. sz6sm10013088pab.5 - gsmtp in C:\Program Files (x86)\Moodle\server\moodle\user\edit.php on line 252
我已經測試Gmail的服務器使用Telnet我的,這是在25號端口聽得很好。 我已經完成了這個錯誤所告知的所有內容以及其他相關帖子
嘗試: 「SSL://smtp.gmail.com」,但它只會提供以下錯誤:
Warning: mail() [function.mail]: Failed to connect to mailserver at "ssl://smtp.gmail.com" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Program Files (x86)\Moodle\server\moodle\user\edit.php on line 252
即使openssl.dll在php.ini中被註釋掉。
;extension=php_tidy.dll
extension=php_xmlrpc.dll
;extension=php_openssl.dll;
而且,我已經配置php.ini文件(php.ini中生產和php.ini的發展也):
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = smtp.gmail.com
; http://php.net/smtp-port
smtp_port = 25
; For Win32 only.
; http://php.net/sendmail-from
;sendmail_from = [email protected]
但添加此爲php.ini並沒有多大(因此我使用了set_ini()),因爲服務器會說,「本地主機smtp服務器不能在端口25上配置」,儘管我已經在php.ini中設置了SMTP = smtp.gmail.com。
任何幫助,將不勝感激。 在此先感謝。
嘗試與端口Nº465或587 ...... 在這裏看到:https://support.google.com/mail/answer/13287?hl=en – Eleazan
感謝您的reply.Nah,不working.It被卡在相同的錯誤。 – tbdei
你可以請檢查openssl是否通過運行phpinfo()正確加載?我有一個類似的問題,與openssl.dll一個回來時,我使用的其中一個擴展(php_exif,如果我沒記錯的話)與openssl擴展衝突 – lePunk