I'm using the PHP mailer class and everything is working exactly as I want it to. There is only one problem and it only happens to happen with Yahoo mail. First, here's my code:
$body = "<p>Hello</p>";
$body .= "<p>World</p>";
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->IsHTML(true);
$mail->SMTPAuth = true;
$mail->Hostname = "domain.com";
$mail->Username = "[email protected]"; // your SMTP username
$mail->Password = "Password"; // your SMTP password
$mail->Host = "ssl://smtp.domain.com"; // SMTP server
$mail->Port = "PORT";
$mail->From = $from;
$mail->FromName = $fromname;
$mail->AddAddress($to);
$mail->Subject = $subject;
$mail->Body = $body;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
}
When sending it to a gmail or hotmail address, the mail comes out perfectly as:
Hello
World
But when sending it to a Yahoo address, it comes out as
Hello
World
The body is obviously longer, so it's really hard to read for Yahoo users. Is there a reason for this strange formatting in Yahoo?
Ah, welcome to the masochistic world of HTML emails. Yahoo (at least it used to) strip out margins from paragraph tags, so you will need to manually add them back. Try this:
$body = '<p style="margin-bottom: 15px;">Hello</p>';
$body .= '<p style="margin-bottom: 15px;">World</p>';
That will guarantee consistency across mail platforms. You can check this guide for some compatibility issues.