PHP mail()函数返回false,但没有错误 [英] PHP mail() function returning false, but with no error

查看:142
本文介绍了PHP mail()函数返回false,但没有错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用php的mail()函数将联系表单的电子邮件的简单过程分配给相应的人员。奇怪的是,该表单总是用于处理电子邮件,但有一天这一切都停止了,现在该函数返回false,但根本不给出任何错误。

I am using php's mail() function for the simple process of E-Mailing the input of a contact form to the respective person. The strange thing is that the form always used to process the E-Mails, but one day this all stopped, now the function returns false, but gives no error at all.

该网站在一个共享主机上。当被问及这个问题时,他们建议我使用smtp继电器xx.xxx.x.xxx

The site is on a shared host. When asked about this, they recommended I use the smtp relay xx.xxx.x.xxx

如果我错了,请更正我,但是mail()函数不提供这样做的规定呢?请问HOST机器是否正确配置继电器配置?

Correct me if I am wrong, but the mail() function does not provide provisions for this does it? Surely it is up to the HOST machine to have it's relays configured correctly?

我的问题是:这是否与主机配置错误,或者是我的码?以下是我使用的邮件代码示例:

My question is this: Does this seem like an error with the host config, or is it my code? Here is a sample of the mail code I have used:

$to = "xxx@xxx.co.za"; //to who?
$subject = "Website Contact: $mysubject";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "From: $fname<$email1>\r\n";
$headers .= "Reply-To: $email1\r\n";
$headers .= "Return-Path:$email1\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
$msg2 = nl2br($msg);

$send = mail($to, $subject, $msg2, $headers); //process mail

if(!$send):
  //error stuff here
endif;

非常感谢,
Simon

Many thanks, Simon

@eisberg - 我使用一个自定义的错误处理程序,如下所示:

@eisberg - I use a custom error handler like this:

//error handler function
function customError($errno, $errstr){
$err = "\n".date('Y-m-d H:m:s')." Error: [$errno] $errstr";
$fh = fopen("errlog.txt", 'a+');
fwrite($fh, $err);
fclose($fh);
}
set_error_handler("customError", E_ALL);

这意味着我需要更改 set_error_handler(customError,E_ALL) ; to set_error_handler(customError,-1);

Would that mean I need to change set_error_handler("customError", E_ALL); to set_error_handler("customError", -1); ?

推荐答案


mail()函数返回false,但没有错误

mail() function returning false, but with no error

欢迎到PHP!


这是否似乎是主机配置的错误,还是我的代码?

Does this seem like an error with the host config, or is it my code?

谁知道?


当被问及这个问题时,他们建议我使用smtp中继...

When asked about this, they recommended I use the smtp relay...

的确,你可能应该。仔细查看 SwiftMailer ,这是一款优秀,全面的现代PHP邮件库,可以直接与SMTP服务器通信。它在构建MIME消息方面表现出色,就像您似乎已经精心设计在一起的那样。

Indeed, you probably should. Take a good look at SwiftMailer, an excellent, comprehensive, modern PHP mailing library that can speak directly to that SMTP server. It excels at building MIME messages, like the one you seem to have painstakingly put together above.

其他受欢迎的选项包括 PEAR的邮件 Zend Framework的Zend_Mail ,以及古典经典, PHPMailer

Other popular options include PEAR's Mail, Zend Framework's Zend_Mail, and the classic of classics, PHPMailer.

这篇关于PHP mail()函数返回false,但没有错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆