简体   繁体   English

无法使用PHP发送电子邮件

[英]Unable to Send Email Using PHP

Preview: I have been trying to send an email using Moodle for a long time and finally decided to test sending an email by using a standard PHP mail() function to test if mail is working fine. 预览:我一直在尝试使用Moodle发送电子邮件很长一段时间,最后决定使用标准的PHP mail()函数测试发送电子邮件,以测试邮件是否正常工作。

BUT EVEN PHP DOES NOT SEND AN EMAIL!! 但即使PHP没有发送电子邮件!

Problem Scenario: 问题场景:

This is my code for 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.";

The Error which I get is : 我得到的错误是:

    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

I have tested my gmail server using Telnet and it is listening fine on Port 25. I have done everything that has been told by this error and other related posts 我已经使用Telnet测试了我的gmail服务器,它在端口25上正常收听。我已经完成了此错误和其他相关帖子所告知的所有内容

Tried: "ssl://smtp.gmail.com" but it would simply give the following error: 尝试:“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

even though openssl.dll has been uncommented in PHP.ini. 即使openssl.dll已在PHP.ini中取消注释。

 ;extension=php_tidy.dll
 extension=php_xmlrpc.dll
 ;extension=php_openssl.dll;

Also, I have configured the php.ini file(php.ini-production and php.ini-development also): 另外,我已经配置了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

But adding this to php.ini did not make much of a difference(therefore I resorted to set_ini()) as the server would coninue saying that "localhost smtp server cannot be configured on Port 25" though I had set the SMTP=smtp.gmail.com in php.ini. 但是将这个添加到php.ini并没有太大的区别(因此我使用了set_ini())因为服务器会说“尽管我已经设置了SMTP = smtp,但是无法在端口25上配置localhost smtp服务器”。 php.ini中的gmail.com。

Any help on this would be greatly appreciated. 任何有关这方面的帮助将不胜感激。 Thanks in advance. 提前致谢。

You've configured port 25 for the mail server. 您已为邮件服务器配置了端口25。

The error message you're getting says that it's unable to connect to localhost:25 . 您收到的错误消息表明它无法连接到localhost:25

Therefore you have two options: 因此,您有两种选择:

  1. Install / Properly configure an SMTP server on localhost port 25 在localhost端口25上安装/正确配置SMTP服务器
  2. Change the configuration to different port to which you can connect to: 将配置更改为可以连接到的其他端口:

。

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

This support forum thread may be helpful. 此支持论坛主题可能会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM