PHP - Email not sending as HTML. Why?

前端 未结 1 829
眼角桃花
眼角桃花 2021-01-29 01:29

I am able to send plain text emails from my contact form using php, but I am not able to send the content as HTML. Thought I had added the headers correctly, but apparently ther

相关标签:
1条回答
  • 2021-01-29 02:12

    try this. code is un-tested. and it's been eons since i've written in php so i could have easily mangled some syntax in there.

    $tacos   = "crunchy";
    
    $to      = "tacos4eva@email.com"; 
    $subject = "tacos"; 
    $mail    = "the tacos are $tacos today."; 
    
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
    $headers .= 'From: taco_master@email.com' . "\r\n";
    
    $success = mail($to, $subject, $mail, $headers); 
    
    if ($success) echo "tacos were sent successfully"; 
             else echo "tacos fell on the floor"; 
    

    http://php.net/manual/en/function.mail.php

    from the page...

    When sending mail, the mail must contain a From header. This can be set with the additional_headers parameter, or a default can be set in php.ini.

    <?php
    $to      = 'nobody@example.com';
    $subject = 'the subject';
    $message = 'hello';
    $headers = 'From: webmaster@example.com' . "\r\n" .
        'Reply-To: webmaster@example.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();
    
    mail($to, $subject, $message, $headers);
    ?>
    
    0 讨论(0)
提交回复
热议问题