0

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 = "name@domain.com"; // 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?

user1701252
  • 1,501
  • 1
  • 11
  • 19
  • Is the `

    ` tag removed from the mail at yahoo? Or is the problem the mail client's css formatting? Maybe you should send your own css in the mail.

    – Martin Lantzsch Jan 16 '15 at 21:54

2 Answers2

3

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.

0

There are less possibilities for webmailers like Yahoo to interprete (or manipulate) it when you write it in this way:

$body = "<p>Hello<br /><br />World</p>";
hellcode
  • 2,678
  • 1
  • 17
  • 21