【发布时间】:2013-03-07 09:27:32
【问题描述】:
我想通过本地托管的 php 代码发送电子邮件。
<?php
$email = "myemail@local.com";
$titre = "My subject";
$message = "Text message !";
mail($email, $titre, $message);
?>
当我运行此代码时,我收到以下错误:
Warning: mail() [<a href='function.mail'>function.mail</a>]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\...
我进入了php.ini 文件,它似乎已经配置好了。
[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP = localhost
; http://php.net/smtp-port
smtp_port = 25
我该如何解决这个问题?
谢谢
【问题讨论】:
-
你不能从本地主机发送邮件,在本地主机
eg : google,yahoo...配置一些其他的smtp -
"failed to connect to mailserver"...你已经配置PHP连接到本地主机上的邮件服务器,端口25。你安装了这样的邮件服务器吗?
-
@YogeshSuthar — 不正确!任何连接到网络的计算机都可以发送电子邮件。
-
@YogeshSuthar — 如果您安装 SMTP 服务器并将其配置为侦听该端口 - 是的。
-
@YogeshSuthar — 那里有很多免费的 SMTP 服务器。我通常使用 Postfix。不过,使用您的服务提供商的服务器可能是一个更好的主意。维护 SMTP 服务器可能很棘手(考虑到垃圾邮件发送者会破坏生态系统)。