PHP - Email not sending as HTML. Why?

R0LL

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 there is still a problem.

This is the script I am using:

<?php


    $to = '[email protected]'; 
    $subject = 'From your Web';
    $email = $_REQUEST['email'] ;


    if(filter_var($email, FILTER_VALIDATE_EMAIL)) {
    //if "email" is filled out, send email
        if (!trim($_REQUEST['name']) == "" ) 
        {
            if (!trim($_REQUEST['message']) == "" ) 
            {

                //send email
                $name = $_REQUEST['name'] ;
                $message = $_REQUEST['message'] ;
                $mail = '
                    <html>
                        <body>
                             <table border=1>
                            <tr>
                                <td>Name:</td>
                                <td>'.$name.' </td>
                            </tr>
                            <tr>
                                <td>Email:</td>
                                <td>'.$email.'</td>
                            </tr>
                            <tr>
                                <td>Msg:</td>
                                <td>'.$message.'</td>
                            </tr>
                        </table>
                        </body>
                        </html>
                ';

                $headers  = 'MIME-Version: 1.0' . "\r\n";
                $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

                mail($to, $subject, $mail, "From:" . $email, $headers);
                //mail($to, $subject, "From: " . $name . "/" . $email . " Msg: ".$message, "From:" . $email);
                echo 'Thank you!';

            }
            else{

                echo 'No empty msg';

            }   
        }
        else{

            echo 'This is not a name';
        }
    }
    else{

        echo 'No correct email';
    }

    ?>
gloomy.penguin

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      = "[email protected]"; 
$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: [email protected]' . "\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      = '[email protected]';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: [email protected]' . "\r\n" .
    'Reply-To: [email protected]' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);
?>

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related