Reputation: 15091
I'm running a website loccaly useing WAMP and have installed Test Mail Server Tool to act as a mail server (all it does is saves the messages as .eml files). I've tried opening the messages with Lotus Notes and gmail (web interface) and both do not interpret the HTML, for example instead of having a clickable link they have <a href='localhost'>click here</a>
Did I make a mistake with the headers?
Here is the code I am using
$to = '[email protected]';
$from = 'From: [email protected]';
$subject = 'this is a test';
$message = '<html><head></head><body>Hello. Please follow <a href="http://localhost/proc.php?uid=45ab3">this link</a> to activate your account.'
."r\n".'<a href="http://localhost/proc.php?uid=45ab3"><img src="images/ActivateButton.gif" alt="activate button" />
</body></html>';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; utf-8' . "\r\n";
$headers .= 'From: [email protected]' . "\r\n";
mail($to, $subject, $message, $from, $headers);
By the way, I was stuck not having a mail server since WAMP doesn't come with one and I red on another question someone recommended Test Mail Server Tool. I'm open to using a different one because it doesn't seem popular.
Upvotes: 0
Views: 516
Reputation: 8334
Look at this example , it works for me :
<?
//change this to your email.
$to = "[email protected]";
$from = "[email protected]";
$subject = "Hello! This is HTML email";
//begin of HTML message
$message = "<html>
<body bgcolor=\"#DCEEFC\">
<center>
<b>Looool!!! I am reciving HTML email......</b> <br>
<font color=\"red\">Thanks dud!</font> <br>
<a href=\"http://www.test.com/\">* test.com</a>
</center>
<br><br>*** Now you Can send HTML Email <br> Regards<br>MOhammed Ahmed - Palestine
</body>
</html>";
//end of message
// To send the HTML mail we need to set the Content-type header.
$headers = "MIME-Version: 1.0rn";
$headers .= "Content-type: text/html; charset=iso-8859-1rn";
$headers .= "From: $from\r\n";
//options to send to cc+bcc
//$headers .= "Cc: [email][email protected][/email]";
//$headers .= "Bcc: [email][email protected][/email]";
// now lets send the email.
mail($to, $subject, $message, $headers);
echo "Message has been sent....!";
?>
Upvotes: 0
Reputation: 19367
If you refer to the docs and examples in the docs, you will see that the From information is not a separate argument to mail()
but is included with the additional-headers information.
bool mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )
Remove your $from argument from the call to mail()
.
mail($to, $subject, $message, $headers);
Upvotes: 2