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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T16:09:56+00:00 2026-05-21T16:09:56+00:00

I can send just text fine, just html fine, but when I combine the

  • 0

I can send just text fine, just html fine, but when I combine the two as follows the email sends but the body is empty.

$to = "some@email.com";
$subject = "Welcome";
$boundary = md5(date('U'));

$headers = "From: Company <noreply@email.com>" . "\n".
                   "X-Mailer: PHP/".phpversion() ."\n".
                   "MIME-Version: 1.0" . "\n".
                   "Content-Type: multipart/alternative; boundary=".$boundary. "\n";
                   "Content-Transfer-Encoding: 7bit". "\n";

// TEXT EMAIL PART
$text = "Congratulations";

// HTML EMAIL PART
$html = "<html><body>\n";
$html .= "<div>Congratulations</div>";
$html .= "</body></html>\n";

$message = "Multipart Message coming up" . "\n\n".
           "--".$boundary.
           "Content-Type: text/plain; charset=\"iso-8859-1\"" .
           "Content-Transfer-Encoding: 7bit".
           $text. 
           "--".$boundary. 
           "Content-Type: text/html; charset=\"iso-8859-1\"". 
           "Content-Transfer-Encoding: 7bit". 
           $html.
           "--".$boundary."--";

mail($to, $subject, $message, $headers);    
  • 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-21T16:09:57+00:00Added an answer on May 21, 2026 at 4:09 pm

    You’ve forgotten line breaks after your Content-Type and Content-Transfer-Encoding lines, so the beginnings of your body content are co-mingled with the headers:

           "--".$boundary.
                        ^^^--- missing \n
           "Content-Transfer-Encoding: 7bit".
                                            ^^^--- missing \n\n
           $text. 
    

    As stated in the comments above, use Swiftmailer or PHPMailer to do this. They’ll take care of all the piddle little details, and let you send the entire mail in far fewer lines of code.

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

Sidebar

Related Questions

can some one explain why I face problem with backgroundworker backgroundWorker1_RunWorkerCompleted works just fine
This code works and sends me an email just fine: import smtplib #SERVER =
I'm using C++ and wondering if I can just send an entire int array
I just want to send SMS from my web application in PHP. Can anyone
I can send newsletters to email accounts. I am using div for containing the
I can send any windows application key strokes with PostMessage api. But I can't
Using cURL I can send a GET request with a body. Example: curl -i
I've scoured the web, but, alas, I just can't seem to get Rspec to
I'm currently using JavaMail and Spring to send email in HTML. As it happens,
I can send requests to friends using Multi Friend Request Selector inside my Page

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.