简体   繁体   English

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

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

I am trying to call the mail function, but whenever I put it in the script, the page does not load.我正在尝试调用邮件 function,但是每当我将其放入脚本时,页面都不会加载。

I have the following code for my php.ini file in XAMPP:我的php.ini文件在 XAMPP 中有以下代码:

[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

I have a 64-bit computer, but an error message said it was missing a sendmail_from, so I gave this variable a value.我有一台 64 位计算机,但一条错误消息说它缺少一个 sendmail_from,所以我给这个变量一个值。 I have Mercury running from XAMPP, but I don't know if I configured anything that needs to be configured.我从 XAMPP 运行 Mercury,但我不知道我是否配置了任何需要配置的东西。

I get the following error我收到以下错误

mail(): Failed to connect to mailserver at "localhost" port 80, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() mail():无法在“localhost”端口 80 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或使用 ini_set()

I used the following php code:我使用了以下 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>";
}
?>

Below this is the default html tags.下面是默认的 html 标签。


Update更新

I removed the sendmail_from and set the smtp_port to 25.我删除了sendmail_from并将smtp_port设置为 25。

mail(): Bad Message Return Path i mail(): 错误消息返回路径 i


Related有关的

Learn how to use PhpMailer and don't mess with this embarrassing mail function.了解如何使用 PhpMailer,不要乱搞这个尴尬的邮件 function。

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

With this class you will send all messages with and without authorization, with or without tls/ssl and attachments (files, images).有了这个 class,您将发送所有有和没有授权的消息,有或没有 tls/ssl 和附件(文件、图像)。

:!! :!! Install smtp server: hmailserver on localhost first !!!首先在本地主机上安装 smtp 服务器:hmailserver !!!

https://www.hmailserver.com/download https://www.hmailserver.com/download

And create your domain email mailbox.并创建您的域 email 邮箱。

Regards问候

First, I never heard for mail server listening on port 80. I have XAMPP installed too, but with configured with "smpt_port=25".首先,我从来没有听说过邮件服务器监听端口 80。我也安装了 XAMPP,但配置了“smpt_port=25”。

Second, you have "SMTP=localhost" so in order to send email you must have installed mail server on your machine, for example "Mercury" from XAMPP package.其次,你有“SMTP=localhost”,所以为了发送 email,你必须在你的机器上安装邮件服务器,例如来自 XAMPP ZEFE90A8E604A7C840E88D03A6D8ZF67 的“Mercury”。

Third, it can be very tricky to properly send email using "mail()" function (authentication, spam detection...) so best solution is to avoid usage of "mail()" function and use some robust library/component/script for that.第三,使用“mail()”function(身份验证,垃圾邮件检测......)正确发送 email 可能非常棘手,因此最好的解决方案是避免使用“mail()”ZC1C425268E68385D14ZA7 并使用一些健壮的库/组件/组件/D1ABZA7为了那个原因。

It is good advice by Baranix to learn how to use PhpMailer or SwiftMailer (my favourite) and configure them to target real, well configured mail server on real hosting. Baranix 建议学习如何使用 PhpMailer 或SwiftMailer (我最喜欢的)并将它们配置为针对真实主机上配置良好的真实邮件服务器。

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

Let us learn about the @ symbol, but be warned of a possible fake return status.让我们了解@符号,但要注意可能的虚假返回状态。

People typically try this first though人们通常会先尝试这个

Try Catch Block尝试捕获块

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM