簡體   English   中英

無法使用PHP發送電子郵件

[英]Unable to Send Email Using PHP

預覽:我一直在嘗試使用Moodle發送電子郵件很長一段時間,最后決定使用標准的PHP mail()函數測試發送電子郵件,以測試郵件是否正常工作。

但即使PHP沒有發送電子郵件!

問題場景:

這是我的PHP代碼:

$to = "receiver@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "username150@gmail.com";
$headers = "From:" . $from;
ini_set( "sendmail_from", "username@gmail.com" ); 
ini_set( "SMTP", "smtp.gmail.com" );  
ini_set( "smtp_port", "25" );
ini_set("username","username0@gmail.com"); 
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

我已經使用Telnet測試了我的gmail服務器,它在端口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-production和php.ini-development):

[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 = username@gmail.com

但是將這個添加到php.ini並沒有太大的區別(因此我使用了set_ini())因為服務器會說“盡管我已經設置了SMTP = smtp,但是無法在端口25上配置localhost smtp服務器”。 php.ini中的gmail.com。

任何有關這方面的幫助將不勝感激。 提前致謝。

您已為郵件服務器配置了端口25。

您收到的錯誤消息表明它無法連接到localhost:25

因此,您有兩種選擇:

  1. 在localhost端口25上安裝/正確配置SMTP服務器
  2. 將配置更改為可以連接到的其他端口:

。

  • TLS / STARTTLS的端口:587
  • SSL端口:465

此支持論壇主題可能會有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM