1

I'm using the following code to send an email:

        $to = "****.co.uk";
        $subject = "Membership submission";
        $body = "";

        $date = date('d/m/Y H:i:s');

        $body .= "<b>REF</b>: " . $postId . "<br />";  
        $body .= "<b>On</b>: " . $date . "<br />";
        $body .= "<b>First name</b>: " . $postFirstName . "<br />";
        $body .= "<b>Last name</b>: " . $postLastName . "<br />";
        $body .= "<b>Company name</b>: " . $postCompanyName . "<br />";
        $body .= "<b>Address</b>:<br /> " . nl2br( $postAddress ) . "<br />";
        $body .= "<b>Telephone number</b>: " . $postTelephoneNumber . "<br />";          
        $body .= "<b>Email</b>: " . $postEmail . "<br />";       
        $body .= "<b>Website</b>: " . $postWebsite . "<br />";        
        $body .= "<b>Skills</b>:<br /> " . nl2br( $postSkills ) . "<br />";      
        $body .= "<b>Payment method</b>: " . $postPaying . "<br />";    

        // 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: noreply@*****.co.uk' . "\r\n";

        if ( mail( $to, $subject, $body, $headers ) ) {
        //

In outlook.com and windows 8 mail program it comes through fine. But when sent to my client's desktop outlook program it comes through like this:

Content-type: text/html; charset=iso-8859-1

 From: noreply@***
 X-Brightmail-Tracker: AAAAAQAAAlk=

 <b>REF</b>: 513a8440922ea<br /><b>On</b>: 09/03/2013 00:40:59<br /><b>First
 name</b>: a name<br /><b>Last name</b>: a last name<br /><b>Company name</b>: My
 Company name<br /><b>Address</b>:<br /> an address,<br />

 2,<br />

 3,<br />

 4,<br />

 postcode<br /><b>Telephone number</b>: 521213091<br /><b>Email</b>:
 ****.co.uk<br /><b>Website</b>: site.com<br
 /><b>Skills</b>:<br /> I do not have any skills to assist with.<br />

 <br />

 Sorry<br /><b>Payment method</b>: Bank transfer<br />

Is anything wrong with my code?

I just tried adding this:

Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit

Now the email I receive in outlook.com is in HTML only. so that killed it? Aghh what's the problem here!

Vineet1982
  • 7,730
  • 4
  • 32
  • 67
Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233
  • possible duplicate of [Sending HTML email from PHP](http://stackoverflow.com/questions/3058897/sending-html-email-from-php) – j0k Mar 09 '13 at 11:33

3 Answers3

0

It seems that you are missing the MIME Specifications: Add this:

$header  .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

It's also shown in the PHP-Documentation for the mail-function.

Vineet1982
  • 7,730
  • 4
  • 32
  • 67
0

I'm not sure, but this may be because you are missing the opening <html> and closing </html> tags.

An example in the documentation for the mail() function might help.

Vivek Ghaisas
  • 961
  • 1
  • 9
  • 24
  • No it didn't... I think I added a Title though.. it seemed to work after that? But I just don't believe it.. so not sure what the answer was but it wasn't the html. – Jimmyt1988 Mar 12 '13 at 01:50
0

This is the code-snippet I am using. I works very well.

// Boundary 
$innerboundary ="=_".time()."_=";

// Mail-Header 
$header ="MIME-Version: 1.0\n"; 
$header.="From: sender@mail.com\n"; 
$header.="Reply-To: sender@mail.com\n"; 
$header.="X-Mailer: kmPHP-Mailer\n"; 
$header.="Content-Type: multipart/alternative;\n\tboundary=\"".$innerboundary."\"\n";

// Mail-subject 
$subject ="Subject goes here"; 
$body ="";

// HTML part 
$body.="\n--".$innerboundary."\n"; 
$body.="Content-Type: text/html;\n\tcharset=\"iso-8859-1\"\n"; 
$body.="Content-Transfer-Encoding: base64\n\n"; 
$body.=chunk_split(base64_encode(($html_string_goes_here)))."\n\n"; 
$body.="\n--".$innerboundary."--\n"; 
$body.="\n\n"; 
OptimusCrime
  • 14,662
  • 13
  • 58
  • 96