【发布时间】:2016-01-06 20:20:24
【问题描述】:
警告:mail(): 无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\xampp\htdocs\series\ 中使用 ini_set()第 8 行的 mailoutput\index.php 发送电子邮件时出错。
我在运行 php 代码时收到此消息。我在一个文件夹中有这个,我正在从 thenewboston 对 php 进行 tut。这是我的文件所在的位置 C:\xampp\htdocs\series\mailoutput\index.php
这是我正在运行的代码。
<?php
$to = 'myemail@gmail.com';
$subject = 'This is an email';
$body = 'This is a test email\n\nHope you got it.';
$headers = 'From: someone@gmail.com';
if (mail($to, $subject, $body, $headers))
{
echo 'Email has been sent. '.$to;
}
else
{
echo 'There was an error sending the email.';
}
?>
我的 php.ini 文件有这些设置
SMTP = ssl://stmp.gmail.com
smtp_port = 465
sendmail_from = myemail@gmail.com
sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
在我的 sendmail.ini 文件中,这些是设置
smtp_server=ssl://stmp.gmail.com
smtp_port=465
auth_username=myemail@gmail.com
auth_password=(mypassword)
force_sender=myemail@gmail.com
不知道为什么这不起作用,或者是否有更简单的方法来完成这项工作。
【问题讨论】:
-
不要使用 mail()。使用 phpmailer 或 swiftmailer
-
“不要做卡,做个笨蛋” - @Dagon
-
这些可以免费使用吗?我只是为我正在上的一门课做这件事,不需要在大学上花更多的钱,哈哈。