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 6868561
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T03:26:57+00:00 2026-05-27T03:26:57+00:00

I am trying to send in PHP an HTML email but it always shows

  • 0

I am trying to send in PHP an HTML email but it always shows the sourcecode of the email in the email program. But it should render the html email as html and not show the sourcecode as email content.

I send my emails like this:

$fd = popen("/var/qmail/bin/sendmail -t","w") or die("Couldn't Open Sendmail"); 
    fputs($fd, "To: ".$to2." \n"); 
    fputs($fd, "From: \"Test <test@test.com>\" \n"); 
    fputs($fd, "Subject: ".$subject." \n"); 
    fputs($fd, "X-Mailer: PHP5 \n"); 
    fputs($fd, "Mime-Version: 1.0 \n");
    fputs($fd, " \n");
    fputs($fd, "--".$mime_boundary."");
    fputs($fd, "Content-Type: text/html; charset=\"utf-8\"; boundary=\"".$mime_boundary."\" \n");
    fputs($fd, "Content-Transfer-Encoding: quoted-printable \n");   
    fputs($fd, " \n");
    fputs($fd, $sendmail_body." \n"); 
    fputs($fd, "".$mime_boundary."--");
    pclose($fd);

The content of the html file looks like this:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="de" lang="de">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
<style type="text/css">
body { font: normal 12px Verdana, Arial, Helvetica, sans-serif; }
</style>
</head>
<body>
</body>
</html>

It worked now:

$fd = popen(“/var/qmail/bin/sendmail -t”,”w”) or die(“Couldn’t Open
Sendmail”); fputs($fd, “To: “.$to1.” \n”); fputs($fd, “From:
\”Test \” \n”);
fputs($fd, “Subject: “.$subject.” \n”); fputs($fd, “X-Mailer:
PHP5 \n”); fputs($fd, “Mime-Version: 1.0 \n”);
fputs ($fd, “Content-Type: multipart/alternative; boundary=\””.$mime_boundary.”\” \n”); fputs($fd, ” \n”);
fputs($fd, “–“.$mime_boundary.”\n”); fputs($fd, “Content-Type:
text/html; charset=\”utf-8\” \n”); fputs($fd,
“Content-Transfer-Encoding: quoted-printable \n”); fputs($fd, ”
\n”); fputs($fd, $sendmail_body.” \n”); fputs($fd,
“–“.$mime_boundary.”–\n”); pclose($fd);

And the first line of my html file is empty or I add an \n before the html content.

  • 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-05-27T03:26:58+00:00Added an answer on May 27, 2026 at 3:26 am

    I think you should consider sending multipart since some clients do not support html mails or just prefer plain text:

    $headers = "From: Example <example@example.com>\r\n
        MIME-Version: 1.0\r\n
        Content-Type: multipart/alternative; boundary={$mime_boundary}\r\n
        X-Mailer: PHP5";
    
    $message = "This is a MIME-Message. If you can read this your client does not support the MIME format.\r\n
    \r\n
    {$mime_boundary}\r\n
    Content-Transfer-Encoding: quoted-printable\r\n
    Content-Type: text/plain; charset=utf8;\r\n
    \r\n
    Text Content encoded in quoted printable
    \r\n
    \r\n
    {$mime_boundary}\r\n
    Content-Transfer-Encoding: quoted-printable\r\n
    Content-Type: text/html;charset=utf8;\r\n
    \r\n
    HTML Content encoded in quoted printable
    \r\n
    --{$mime_boundary}";
    
    mail($to, $subject, $message, $headers);
    

    As long as the sendmail path and params are configured correctly in php.ini this will send the mail via sendmail in multipart/alternative type.

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

Sidebar

Related Questions

Hi there I'm trying to send an HTML email through a PHP webform. The
Trying to send a PHP email the easy way but I cannot work out
I am trying to send an HTML mail through PHP, but I can't seem
I am trying to send an email with PHP but I get a weird
I'm trying to send an email with html formatting, but when it arrives (in
I'm trying to send an email in Java but when I read the body
I am trying to send an email from a site I am building, but
I'm trying to accomplish the following, I'm sending a HTML email using PHP Mailer
I am trying to send an email message with data collected from an html
I'm trying to send out a Plain/HTML multipart email out and I'm currently using

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.