邮件返回错误

php
2022-08-30 21:58:46

我目前正在工作中使用定制的库。直到刚刚兴起,图书馆才完美地工作。它显然从今天开始返回错误。

库本身基本上是函数邮件的包装器。它建立了“边界”部分和一切。

由于课程足够大,我不会在这里发布它...但是我想知道,从理论上讲,为什么邮件会返回假的是什么原因?

  • SMTP 是在 PHP 中设置的.ini
  • 发件人在标头中设置
  • 发件人的形式为:sender<sender@email.com>
  • 所有内容都已正确发送(正文+标头+主题)
  • 假设mail( )在网站上正常工作,但在这个特定的页面上却不能。我知道它一定来自我,但有一个地方开始寻找会很有趣。
  • 哦,是的,图书馆是无证的。

[编辑]只是发现一个较小的函数仍然不起作用,然后我会把它打印出来:

function send_html($from, $email, $subject = "AUCUN", $message, $cc = "", $bcc ="", $priotity = "3") {
    $headers = "";
    $headers .= "MIME-Version: 1.0\r\n"; 
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";

    if (strpos($from, "ourwebsite.com") != false || strpos($from, "rencontresportive.com") != "") {
        $headers .= "From: Ourwebsite.com <" . $from . ">\r\n";
    } else {
        $headers .= "From: " . $from . " <" . $from . ">\r\n";
    }

    $headers .= "X-Sender: <" . $from . ">\r\n";
    $headers .= "X-Priority: " . $priotity . "\r\n";
    $headers .= "X-Mailer: PHP\r\n";
    $headers .= "Return-Path: <admin@ourwebsite.com>\r\n";

    if ($cc != "") {
        $headers .= "cc:" . $cc . "\r\n";
    }
    if ($bcc != "") {
        $headers .= "bcc:" . $bcc . "\r\n";
    }
        if (mail($email, $subject, $message, $headers)) {
        return true;
    } else {
        return false;
    }
}

我用以下方式称呼它:

send_html(contact@ourwebsite.com, me@me.com, utf8_decode("the subject"), "<h1>test</h1>");

答案 1

我只是遇到了同样的问题。php 升级后,mail 函数始终返回 false。

我用这个小片段来检查它:

<?php
error_reporting(E_ALL|E_STRICT);
ini_set('display_errors', 1);
echo 'I am : ' . `whoami`;
$result = mail('myaddress@mydomain.com','Testing 1 2 3','This is a test.');
echo '<hr>Result was: ' . ( $result === FALSE ? 'FALSE' : 'TRUE') . $result;
echo '<hr>';
echo phpinfo();

解决方案是在我的php中为“sendmail_from”和“sendmail_path”设置一个值.ini。在我的情况下,正确的值是:

sendmail_from = "no-reply@mydomain.net"
sendmail_path = "/usr/sbin/sendmail -t -i"

(我使用的是 CentOS 5.3 和 Zend Server CE。

您可以使用 ini_set() 来设置 'sendmail_from' 的值,但 'sendmail_path' var 必须在 php.ini 或 http.conf 中设置。


答案 2

我遇到了类似的问题,即使电子邮件成功接收,邮件功能也始终返回false。

我在php配置文件php中找到.ini,我已经设置了

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.
sendmail_path = "/usr/sbin/sendmail -t -i -f "care@mydomain.com"

我已将其更改为以下内容

; For Win32 only.
;sendmail_from = me@example.com

; For Unix only.
sendmail_path = /usr/sbin/sendmail -t -i -f care@mydomain.com

根据这个sendmail_from是 win32 ,所以在 *unix OS 中,我们需要设置值,如sendmail_path变量所示。

问候米内什


推荐