[英]SMTP server problems, PHP mail
i have installed Apache and php5 on windows 8.1, but can't send mail from my localhost website, the message that appears "Warning: mail() [function.mail]: 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:\\WebServer\\Apache2.2\\htdocs\\WebContent\\mailForm.php on line 22". 我已经在Windows 8.1上安装了Apache和php5,但是无法从我的本地主机网站发送邮件,该消息显示为“警告:mail()[function.mail]:无法在“本地主机”端口25上连接到邮件服务器,请验证您在php.ini中的“ SMTP”和“ smtp_port”设置,或在第22行的C:\\ WebServer \\ Apache2.2 \\ htdocs \\ WebContent \\ mailForm.php中使用ini_set()。 The php code is below, i guess it's ok since it does the 'echos' correctly.
php代码在下面,我猜没问题,因为它正确执行了“ echos”。 Someone can give any tips about what's happening?
有人可以提供有关发生情况的任何提示吗? Thanks.
谢谢。
<?php
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$message = $_POST['message'];
$to = "myemail@example.com";
$subject = "New_message";
if (($first_name == "") || ($last_name == "") || ($email == "") || ($message == ""))
{
echo '<script type="text/javascript">alert("Fill in all fields")</script>';
}
else
{
mail($to, $subject, $message, "From:" . $first_name . $last_name);
echo "Sucess;
}
?>
Are you sure there is a mail server running on the host where your PHP is running? 您确定在运行PHP的主机上运行着邮件服务器吗? You mentioned that you installed apache and PHP, but you did not mention that you installed a mail server.
您提到安装了apache和PHP,但是没有提到安装了邮件服务器。 If there is no mail server installed, then that's your problem.
如果没有安装邮件服务器,那就是您的问题。
If there is in fact a mail server running on the host, then it means that PHP is not configured correctly to find it. 如果实际上主机上正在运行邮件服务器,则意味着未正确配置PHP来查找它。 Create a small script like below, which uses
phpinfo()
to print out all of your PHP environment variables: 创建一个如下所示的小脚本,该脚本使用
phpinfo()
打印所有PHP环境变量:
<? phpinfo(); ?>
Check the value of sendmail_path
. 检查
sendmail_path
的值。 Is this the correct location of the mail server on the host? 这是主机上邮件服务器的正确位置吗? If not, change your php.ini to point to the correct location.
如果不是,请更改您的php.ini以指向正确的位置。
If in fact there is not a mail server running on the host, then you can either install one, or you can work around the problem by sending mail through a mail server hosted elsewhere (such as smtp.gmail.com if you have a gmail account). 如果实际上主机上没有运行邮件服务器,则可以安装一个,也可以通过通过其他位置(例如smtp.gmail.com)托管的邮件服务器发送邮件来解决此问题。帐户)。 This can be done using phpmailer.
这可以使用phpmailer完成。 See send email using Gmail SMTP server through PHP Mailer as an example.
请参阅通过PHP Mailer使用Gmail SMTP服务器发送电子邮件的示例。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.