简体   繁体   English

使用PHP发送邮件不起作用

[英]Sending mail with PHP not working

My script to send an email via PHP is not working and I don't know why as there is no specific error. 我的通过PHP发送电子邮件的脚本不起作用,我也不知道为什么,因为没有特定的错误。 Please advise: 请指教:

test@test.com is replaced with my real email address. test@test.com被替换为我的真实电子邮件地址。

udrew_email("test@test.com", $_REQUEST["txtEmail"], "Gears Message", $_REQUEST["txtName"], $_REQUEST["txtMessage"]);

<?php
function udrew_email($strTo, $strFromEmail, $strSubject, $strFromName, $strBody)
{
$strHeaders = "From: " . $strFromName . "<" . $strFromEmail . ">" . "\r\n";
if (mail($strTo, $strSubject, $strBody, $strHeaders)) {
    echo("<p>Message successfully sent!</p>");
} else {
    echo("<p>Message delivery failed.</p>");
}
}
?>

I get "Message delivery failed." 我收到“消息传递失败。”

I've also tried placing constants in all the variables instead of requesting from my form. 我也尝试过将常量放置在所有变量中,而不是从表单中请求。

Any help would be appreciated. 任何帮助,将不胜感激。 Thanks. 谢谢。

mail() returns false if it was unable to handle the email over to an smtp server. 如果无法处理发送到smtp服务器的电子邮件,则mail()返回false。 On unix, that'd be the local sendmail/postfix/exim. 在Unix上,这将是本地sendmail / postfix / exim。 On Windows, it's whatever smtp server is configured in php.ini SMTP and smtp_port options. 在Windows上,无论是在php.ini SMTPsmtp_port选项中配置的smtp服务器。

That can be because the smtp server isn't running or is mis-configured. 这可能是因为smtp服务器未运行或配置错误。 It can also be because the email is so badly formed the server rejects it outright without even TRYING to deliver it onwards. 也可能是因为电子邮件的格式如此糟糕,服务器完全拒绝了它,甚至没有尝试将其继续发送。

Check and make sure that your mail server is running, and that you have one installed and set up. 检查并确保您的邮件服务器正在运行,并且已安装并设置了一个。 If it is then check the log files for your mail server. 如果是,则检查您的邮件服务器的日志文件。

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

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