为什么邮件功能停止 php 脚本而不是发送邮件?

Why does the mail function stop the php script instead of sending the mail?

我正在尝试调用邮件功能,但每当我将其放入脚本中时,页面都无法加载。

我在 XAMPP 中的 php.ini 文件中有以下代码:

[mail function]
; For Win32 only.
; http://php.net/smtp
SMTP=localhost
; http://php.net/smtp-port
smtp_port=80
auth_username = XX_MYEMAIL_XX
auth_password = XXXXX_MYPASSWORD_XX

我有一台 64 位计算机,但是一条错误消息说它缺少一个 sendmail_from,所以我给这个变量赋值。我有Mercury运行来自XAMPP,但我不知道我是否配置了任何需要配置的东西。

我收到以下错误

mail(): Failed to connect to mailserver at "localhost" port 80, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

我使用了以下 php 代码:

<?php     
$header = "From: varunsingh87@yahoo.com";
$to_email = 'VSpoet49@gmail.com';
$subject = 'Testing PHP Mail';
$message = 'This mail is sent using the PHP mail function';
if (mail($to_email, $subject, $message)) {
 echo "<p>Email sent!</p>";
} else {
 echo "<p>Email not sent.</p>";
}
?>

下面是默认的 html 标签。


更新

我删除了 sendmail_from 并将 smtp_port 设置为 25。

mail(): Bad Message Return Path i


相关

http://php.net/manual/language.operators.errorcontrol.php

让我们了解一下 @ 符号,但要注意可能存在伪造的 return 状态。

人们通常会先尝试这个

Try Catch Block

学会PhpMailer的使用,别乱用这个尴尬的邮件功能

https://github.com/PHPMailer/PHPMailer/wiki/Tutorial

有了这个 class,您将发送所有经过授权和未经授权的消息,带或不带 tls/ssl 和附件(文件、图像)。

!!!首先在本地主机上安装 smtp 服务器:hmailserver !!!

https://www.hmailserver.com/download

并创建您的域电子邮件邮箱。

此致

首先,我从来没有听说过邮件服务器监听 80 端口。 我也安装了 XAMPP,但是配置了 "smpt_port=25"。

其次,您有 "SMTP=localhost",因此为了发送电子邮件,您必须在计算机上安装邮件服务器,例如 XAMPP 包中的 "Mercury"。

第三,使用 "mail()" 功能(身份验证、垃圾邮件检测...)正确发送电子邮件可能非常棘手,因此最好的解决方案是避免使用 "mail()" 功能并使用一些强大的功能library/component/script 为此。

Baranix 的好建议是学习如何使用 PhpMailer 或 SwiftMailer(我的最爱)并将它们配置为针对真实主机上配置良好的真实邮件服务器。