Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8416719
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T01:50:40+00:00 2026-06-10T01:50:40+00:00

I made an HTML e-mail send with PHP, but my client receives this as

  • 0

I made an HTML e-mail send with PHP, but my client receives this as pure code. Here is the PHP code to send the mail:

$subject = 'HTML e-mail test';
$message = '<html>
    <body>
        <h1>TEST</h1>
    </body>
</html>';
$headers = "MIME-Version: 1.0\r\n"; 
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= "To: <".$to.">\r\n"; 
$headers .= "From: <".$email.">\r\n";

$mailb = mail($to, $subject, $message, $headers);

It works fine for me, but they receive it as:

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

To: <email@email.com>
From: <email@email.com>

<html>
    <body>
        <h1>TEST</h1>
    </body>
</html>

Is there something wrong with my headers? Or is it their Outlook?
How can I fix this problem?
Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T01:50:41+00:00Added an answer on June 10, 2026 at 1:50 am

    I see:

    Content-typetext/html; charset=iso-8859-1
    

    where I should see:

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

    Is that a cut/paste error? In your code, or in your result?

    Note that you probably want to include both text/plain and text/html types in a multipart message, since HTML-only mail often gets high spam scores (using SpamAssassin, SpamBouncer, etc).

    UPDATE #1:

    It appears that the \r\n is being interpreted as two newlines instead of one. Different platforms may have different bugs in their implementation of SMTP. It’s possible that you can get away with changing your line endings to just \n. If that works with your system, don’t rely on it, as it may not work on a different system.

    Also, consider switching to a different method for sending mail. phpMailer and SwiftMailer are both recommended over PHP’s internal mail() function.

    UPDATE #2:

    Building on Incognito’s suggestion, here’s code you might use to organize your headers better, as well as create a plaintext part:

    filter_var($to, FILTER_VALIDATE_EMAIL) or die("Invalid To address");
    filter_var($email, FILTER_VALIDATE_EMAIL) or die("Invalid From address");
    
    $subject = 'HTML e-mail test';
    
    $messagetext = 'TEST in TEXT';
    
    $messagehtml = '<html>
        <body>
            <h1>TEST</h1>
            <p>in HTML</p>
        </body>
    </html>';
    
    // We don't need real randomness here, it's just a MIME boundary.
    $boundary="_boundary_" . str_shuffle(md5(time()));
    
    // An array of headers. Note that it's up to YOU to insure they are correct.
    // Personally, I don't care whether they're a string or an imploded array,
    // as long as you do input validation.
    $headers=array(
        'From: <' . $email . '>',
        'MIME-Version: 1.0',
        'Content-type: multipart/alternative; boundary="' . $boundary . '"',
    );
    
    // Each MIME section fits in $sectionfmt.
    $sectionfmt = "--" . $boundary . "\r\n"
          . "Content-type: text/%s; charset=iso-8859-1\r\n"
          . "Content-Transfer-Encoding: quoted-printable\r\n\r\n"
          . "%s\n";
    
    $body = "This is a multipart message.\r\n\r\n"
          . sprintf($sectionfmt, "html", $messagehtml)
          . sprintf($sectionfmt, "plain", $messagetext)
          . "--" . $boundary . "--\r\n";
    
    $mailb = mail($to, $subject, $body, implode("\r\n", $headers));
    

    I’m not saying this is The Right Way to do this by any means, but if the strategy appeals to you, and you think you can maintain code like this after not having looked at it for 6 or 12 months (i.e. it makes sense at first glance), then feel free to use or adapt it.

    Disclaimer: this is untested, and sometimes I make typos … just to keep people on their toes. 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a html file, but when I upload and test it, I
The html of this script is made with list items http://www.jeremymartin.name/projects.php?project=kwicks Where can I
I made a countdown timer and coded this in with HTML and CSS, but
I saw this HTML minifier in Ajaxian and it made me wonder if its
I need to send simple html-message with JavaMail. And when I tried to find
I made a PHP script for a form, but dont't know how to get
I have made asp.net webservice in C# to send mail on given mailid as
I made a PHP page that looks up Constant Contact e-mail addresses in a
I made an html file called test.html then I navigated to it as http://site.com/test.html?test1=a
Please excuse the simplicity and length of this, but I have a little test

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.