Failed to send HTML mails using PHP mail()

前端 未结 3 968
借酒劲吻你
借酒劲吻你 2020-12-07 05:08

Strange things happening to me. I\'m trying to send a HTML mail, using the php mail() function, but no luck here. Even when I copy/paste a piece of code literal

相关标签:
3条回答
  • 2020-12-07 05:49

    We can't see where the variable $email was set, but I'm guessing that there might be an extra line break at the end of your $email variable. This would have the effect of putting in two linebreaks after the From: header and before the Reply-to: , which signals the start of the body of the message and the completion of the headers.

    Try:

    $email = trim($email);
    

    before constructing the message. Since there appears to be an extra line break after the Reply-to header as well, my case is even stronger for an extra break in $email.

    UPDATE

    Also try changing the linebreaks to PHP's native format on the system where the code will run. This is done by replacing \r\n with PHP_EOL

        $headers = "From: " . $email . PHP_EOL;
        $headers .= "Reply-To: ". $email . PHP_EOL;
        $headers .= "MIME-Version: 1.0" . PHP_EOL;
        $headers .= "Content-Type: text/html; charset=ISO-8859-1" . PHP_EOL;
    
    0 讨论(0)
  • 2020-12-07 06:02

    Here is a useful link to sending html emails in php

    http://blog.twigahost.com/how-to-send-html-email-with-php/

    0 讨论(0)
  • 2020-12-07 06:02

    I recommend you to use a mailer class. They give you the possibility to use smtp auth, so every mail will be passed through. A few examples:

    • http://phpmailer.worxware.com/
    • http://swiftmailer.org/
    • http://framework.zend.com/manual/en/zend.mail.html
    0 讨论(0)
提交回复
热议问题