1

I've been working through this thread here: Sending HTML email from PHP

For the last 5 hours and for some reason cannot get my PHP to generate HTML mail.

Here's what I have:

// Construct Mail:
$message = "<html><body>Some text<br />New line<p>New para</p></body></html>";
// Send Mail:
$to         = "$UserMail";
$subject        = "[Skills Exchange Network] Event Created";
$header     = 'MIME-Version: 1.0' . "\r\n";
$header     .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers    .= 'From: Skills Exchange Network <Mail Address is here>' . "\r\n";
$headers    .= 'Cc: Skills Exchange Network <Mail Address is here>' . "\r\n";
$SendMail   = mail($to,$subject,$message,$headers);

Here's what I receive:

From Skills Exchange Network rnCc: Skills Exchange Network rn

I'm truly at a loss...

Here's what I have now:

// Construct Mail:
$message = "<html><body>Some text<br />New line<p>New para</p></body></html>";

// Send Mail:
$to         = "$UserMail";
$subject        = "[Skills Exchange Network] Event Created";

// To send HTML mail, the Content-type header must be set
$headers     = "MIME-Version: 1.0" . "\r\n";
$headers    .= "Content-Type: text/html; charset=ISO-8859-1" . "\r\n";

// Additional Headers:
$headers    .= "From: Skills Exchange Network <info@skillsexchangenetwork.net>" . "\r\n";
$headers    .= "Cc: Skills Exchange Network <info@skillsexchangenetwork.net>" . "\r\n";
$SendMail   = mail($to, $subject, $message, $headers);

And here's what I receive:

Subject: [Skills Exchange Network] Event Created
MIME-Version: 1.0rnContent-Type: text/html; charset=ISO-8859-1rnFrom: Skills Exchange     Network <info@skillsexchangenetwork.net>rnCc: Skills Exchange Network <info@skillsexchangenetwork.net>rn
Message-Id: <E1UzptE-0003e1-Fs@wdt.webserversystems.com>
From: skillsex@wdt.webserversystems.com
Date: Thu, 18 Jul 2013 10:13:08 -0500
X-Antivirus: AVG for E-mail 2013.0.3349 [3204/6500]
X-AVG-ID: ID58DD9571-36429B43

<html><body>Some text<br />New line<p>New para</p></body></html>
Community
  • 1
  • 1
Harlequin
  • 25
  • 5
  • Best is to use tables for email markup – DarkBee Jul 18 '13 at 13:36
  • Is this the e-mail body you are receiving or is this the subject? – Tash Pemhiwa Jul 18 '13 at 13:43
  • There are 2 things at fault: The headers and the body. I get the mail but with malformed headers and the HTML comes as plain text. Probably because the headers are wrong. – Harlequin Jul 18 '13 at 15:16
  • Use a proper library like SwiftMailer. There's no good reason to do it manually with `mail()`. – ceejayoz Jul 18 '13 at 15:24
  • I've been doing it this way as it's code running on the server. Are you suggesting SwiftMailer for a specific reason...? Also, as much as I'd like to use SwiftMailer it won't run within my system. – Harlequin Jul 18 '13 at 15:46

3 Answers3

1

You are naming $headers as $header and because of that your content-type is not embedding.

$headers     = 'MIME-Version: 1.0' . "\r\n";
$headers    .= 'Content-Type: text/html; charset=ISO-8859-1' . "\r\n";
$headers    .= 'From: Skills Exchange Network <Mail Address is here>' . "\r\n";
$headers    .= 'Cc: Skills Exchange Network <Mail Address is here>' . "\r\n";
Yogesh Suthar
  • 30,424
  • 18
  • 72
  • 100
  • Thanks Yogesh I implemented what you suggested: I now still get an error in the headers. MIME-Version: 1.0rnContent-Type: text/html; charset=ISO-8859-1rnFrom: Skills Exchange Network rnCc: Skills Exchange Network rn Clearly I still have an issue. – Harlequin Jul 18 '13 at 14:56
  • In fact, it's not doing two things: Breaking the headers apart and formatting the HTML. I get the mail OK but not formatted correctly or with the headers loading correctly. – Harlequin Jul 18 '13 at 15:07
  • Here's what I have now // Construct Mail: $message = "HTML code here"; // Send Mail: $to = "$UserMail"; $subject = "[Skills Exchange Network] Event Created"; // To send HTML mail, the Content-type header must be set $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-Type: text/html; charset=ISO-8859-1" . "\r\n"; // Additional Headers: $headers .= "From: Skills Exchange Network " . "\r\n"; $headers .= "Cc: Skills Exchange Network " . "\r\n"; $SendMail = mail($to, $subject, $message, $headers); – Harlequin Jul 18 '13 at 15:15
0

Maybe if you put the 's' consequently at the end of $header?

Thomas Leu
  • 826
  • 4
  • 13
0

PHPMailer could be a useful solution.

somejkuser
  • 8,856
  • 20
  • 64
  • 130
  • I've been using that and have even used code from a previous page I wrote that works perfectly but get these errors. – Harlequin Jul 18 '13 at 14:58