我如何修复 PHP 上的 mail() 函数?
How i can fix mail() function on PHP?
我将 Internet 信息服务 (IIS) 与 PHP 一起使用。但是 mail() 函数似乎不起作用。
起初我试图修复 php.ini。然后我下载了hMailServer。现在它显示 "Your message has been sent!" 但我的收件箱中没有收到任何消息。我还检查了垃圾邮件收件箱。但是我什么也找不到。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
$name = $_POST['name'];
$email = "yunishuseynzade1102@gmail.com";
$message = "Hello how are you?";
$from = 'dj.yunis.official@gmail.com';
$to = 'yunishuseynzade1102@gmail.com';
$subject = 'Customer Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
?>
您的 4 Parameter($from) 是错误的,因为它需要一个包含 header 信息的字符串。
您只需 post 一封电子邮件即可。
将您的 $from 更改为:
$from = 'From: dj.yunis.official@gmail.com';
在 IIS 中配置 SMTP 电子邮件:
- 打开 iis 管理器。
- 功能视图,双击 SMTP 电子邮件。
- 在 SMTP 电子邮件页面上,在电子邮件地址文本框中键入发件人的电子邮件地址。
- 在 SMTP 电子邮件页面上,select任何发送方式。
- 将电子邮件发送到 SMTP 服务器:
- 如果将电子邮件存储在取件目录中 selected,请键入批处理
在取件目录中存储电子邮件文本框中的电子邮件位置。
- 单击“操作”窗格中的“应用”。
在 php.ini 文件中设置以下设置:
[mail function]
SMTP=localhost
sendmail_from = string
smtp_port=25
更新:
您需要检查您的垃圾邮件文件夹。
下面是我的工作示例:
我的邮件发送代码:
我将 Internet 信息服务 (IIS) 与 PHP 一起使用。但是 mail() 函数似乎不起作用。 起初我试图修复 php.ini。然后我下载了hMailServer。现在它显示 "Your message has been sent!" 但我的收件箱中没有收到任何消息。我还检查了垃圾邮件收件箱。但是我什么也找不到。
<?php
error_reporting(-1);
ini_set('display_errors', 'On');
set_error_handler("var_dump");
$name = $_POST['name'];
$email = "yunishuseynzade1102@gmail.com";
$message = "Hello how are you?";
$from = 'dj.yunis.official@gmail.com';
$to = 'yunishuseynzade1102@gmail.com';
$subject = 'Customer Inquiry';
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
if (mail($to, $subject, $body, $from)) {
echo '<p>Your message has been sent!</p>';
} else {
echo '<p>Something went wrong, go back and try again!</p>';
}
?>
您的 4 Parameter($from) 是错误的,因为它需要一个包含 header 信息的字符串。 您只需 post 一封电子邮件即可。 将您的 $from 更改为:
$from = 'From: dj.yunis.official@gmail.com';
在 IIS 中配置 SMTP 电子邮件:
- 打开 iis 管理器。
- 功能视图,双击 SMTP 电子邮件。
- 在 SMTP 电子邮件页面上,在电子邮件地址文本框中键入发件人的电子邮件地址。
- 在 SMTP 电子邮件页面上,select任何发送方式。
- 将电子邮件发送到 SMTP 服务器:
- 如果将电子邮件存储在取件目录中 selected,请键入批处理 在取件目录中存储电子邮件文本框中的电子邮件位置。
- 单击“操作”窗格中的“应用”。
在 php.ini 文件中设置以下设置:
[mail function]
SMTP=localhost
sendmail_from = string
smtp_port=25
更新:
您需要检查您的垃圾邮件文件夹。
下面是我的工作示例:
我的邮件发送代码: