1

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.

2 Answers 2

2

It should be

 if(mail($email_to, $email_subject, $message, $headers)){ ...

You've got $message and $headers in the wrong order.

Sign up to request clarification or add additional context in comments.

Comments

1

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

2 Comments

It makes no difference at all.
You put that inside your code right, inside the if statement? Did the call succeed ? Did you get a response of 'sent'?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.