解决windows系统下php.ini邮件配置正确不发送邮件的问题

  • A+
所属分类:Windows
高性能企业级服务器首台5折

问题现象

php.ini邮件配置正确但不发送邮件。报错如下


1
Warning: mail() [function.mail]: SMTP<span class="hljs-built_in"> server </span>response: 530 5.7.0 Must issue a STARTTLS command first

问题原因

php mail()函数不可用,需要安装sendmail 。

 

解决方案

1.从http://glob.com.au/sendmail/下载sendmail.zip

2.解压到C:下,例如:【C:\php\sendmail】最好短路径,长路径名有可能产生问题。

3.修改【php.ini】如下


1
<span class="hljs-attr">sendmail_path</span> = <span class="hljs-string">"C:\wamp\sendmail\sendmail.exe -t"</span>

4.根据自己的配置环境修改【sendmail.ini】。

第一次最好启用debug.log_file,error_logfile,以查看sendmail是否生效。

5.重启apache

用sendmail结合其它的smtp服务器,如smtp.163.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。

php.ini配置 (以用163邮箱为例)


1
2
3
4
5
<span class="hljs-section">[mail function]</span>
<span class="hljs-comment">; For Win32 only. </span>
<span class="hljs-attr">SMTP</span> = smtp.<span class="hljs-number">163</span>.com
<span class="hljs-attr">smtp_port</span> = <span class="hljs-number">25</span>
<span class="hljs-comment">; For Win32 …… </span>

用sendmail结合其它的smtp服务器,如smtp.163.com来实现发邮件。现在大部分邮箱都要求smtp验证,所以要在sendmail.ini中加入用户名和密码。

php.ini配置 (以用163邮箱为例)


1
2
3
4
5
6
7
8
<span class="hljs-section">[mail function]</span>
<span class="hljs-comment">; For Win32 only. </span>
<span class="hljs-attr">SMTP</span> = smtp.<span class="hljs-number">163</span>.com
<span class="hljs-attr">smtp_port</span> = <span class="hljs-number">25</span>
<span class="hljs-comment">; For Win32 only. </span>
<span class="hljs-attr">sendmail_from</span> = <span class="hljs-number">4</span>u4v@<span class="hljs-number">163</span>.com
<span class="hljs-comment">; For Unix only. You may supply arguments as well (default: “sendmail -t -i”). </span>
<span class="hljs-attr">sendmail_path</span> = “D:\xampp\sendmail\sendmail.exe -t”

主要配置三项,【smtp】、【smtp_port】和【sendmail_path】

【sendmail.ini】配置 


1
2
3
4
5
6
7
[sendmail]
; you must change mail.mydomain.com <span class="hljs-keyword">to</span> your smtp<span class="hljs-built_in"> server </span>
<span class="hljs-attribute">smtp_server</span>=smtp.163.com
<span class="hljs-attribute">smtp_port</span>=25
<span class="hljs-attribute">auth_username</span>=yourusername
<span class="hljs-attribute">auth_password</span>=yourpassword
<span class="hljs-attribute">force_sender</span>=yourusername@163.com

以上都是已163为例子的,请更具自己的实际需要修改自己的邮箱配置。

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: