Reputation: 14490
I am trying to send an email with PHP but I get a weird error.
In the PHP I have:
<?php
mail($email_to, $email_subject, $headers, $message);
$email_to = '[email protected]';
$email_subject = 'Hello World';
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = '<html><body>';
$message .= '<table rules="all" style="border-color: #666;" cellpadding="10">';
$message .= "<tr><td><strong>Email:</strong> </td><td>" . strip_tags($_POST['test1']) . "</td></tr>";
$message .= "<tr><td><strong>Message:</strong> </td><td>" . strip_tags($_POST['test2']) . "</td></tr>";
$message .= "</table>";
$message .= '</body></html>';
if(mail($email_to, $email_subject, $headers, $message)){
echo 'sent';
}else{
echo 'failed';
}
?>
With this I receive as a plain text:
<html><body><table rules="all" style="border-color: #666;" cellpadding="10"><tr><td>
<strong>Email:</strong> </td><td>[email protected]</td></tr><tr><td>
<strong>Message:</strong> </td><td>hello world</td></tr></table></body></html>
From: [email protected]
MIME-Version: 1.0
Content-Type: text/html; charset=ISO-8859-1
Can anyone spot what I'm I doing wrong? I tested this on 2 different servers with the same results.
Upvotes: 1
Views: 247
Reputation: 34043
You have mixed up the position of the $message and $headers. Try this instead mail($email_to, $email_subject, $message, $headers)
http://php.net/manual/en/function.mail.php
Upvotes: 1
Reputation: 6992
It should be
if(mail($email_to, $email_subject, $message, $headers)){ ...
You've got $message and $headers in the wrong order.
Upvotes: 2