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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T04:08:28+00:00 2026-05-14T04:08:28+00:00

I am sending info to target email via PHP native mail() method right now.

  • 0

I am sending info to target email via PHP native mail() method right now. Everything else works fine but the table part troubles me the most. See sample output :

Dear Michael Mao :
Thank you for purchasing flight tickets with us, here is your receipt :

Your tickets will be delivered by mail to the following address :
Street Address 1 : sdfsdafsadf sdf
Street Address 2 :  N/A
City  : Sydney State : nsw Postcode : 2
Country : Australia
Credit Card Number : *************1234

Your purchase details are recorded as :

<table><tr><th class="delete">del?</th><th class="from_city">from</th><th class="to_city">to</th><th class="quantity">qty</th><th class="price">unit price</th><th class="price">total price</th></tr><tr class="evenrow" id="Sydney-Lima"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Lima</td><td>1</td><td>1030.00</td><td>1030</td></tr><tr class="oddrow" id="Sydney-Perth"><td><input name="isDeleting" type="checkbox"></td><td>Sydney</td><td>Perth</td><td>3</td><td>340.00</td><td>1020</td></tr><tr class="totalprice"><td colspan="5">Grand Total Price</td><td id="grandtotal">2050</td></tr></table>

The source of table is directly taken from a webpage, exactly as the same. However, Gmail, Hotmail and most of other emails will ignore to render this as a table.

So I am wondering, without using Outlook or other email sending agent software, how could I craft a embedded table for the PHP mail() method to send?

Current code snippet corresponds to table generation :

$purchaseinfo   = $_POST["purchaseinfo"];
//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";

//must send json response back to caller ajax request
if(mail($email, 'Your purchase information on www.hardlyworldtravel.com', $emailbody, $headers))
    echo json_encode(array("feedback"=>"successful"));
else echo json_encode(array("feedback"=>"error"));

Any hints and suggestions are welcomed, thanks a lot in advance.

Edited :

$headers =  'From: fake@hardlyworldtravel.com' . "\r\n" .
        'Reply-To: fake@hardlyworldtravel.com' . "\r\n" .
        'X-Mailer: PHP/' . phpversion();

//carft body of email to a human readable format
function buildEmailBody()
{
    global  $firstname, $lastname, $address1, $address2, $city, $state, $postcode, $country,
        $cardnum, $email, $purchaseinfo;

$stringBuilder = "";        // * there is not such a thing as string builder in PHP

$stringBuilder .= "Dear " .$firstname ." " .$lastname ." :\n";
$stringBuilder .= "Thank you for purchasing flight tickets with us, here is your receipt :\n\n";
$stringBuilder .= "Your tickets will be deliverd by mail to the following address : \n";
$stringBuilder .= "Street Address 1 : " .$address1 ."\n";
$stringBuilder .= ($address2!="") ? "Street Address 2 : " .$address2 ."\n" : "Street Address 2 :  N/A\n";
$stringBuilder .= "City  : " .$city;
$stringBuilder .= ($state!="") ? "State : " .$state : "State : N/A ";
$stringBuilder .= "Postcode : " .$postcode ."\n";
$stringBuilder .= "Country : " .$country ."\n";
$stringBuilder .= "Credit Card Number : " .$cardnum ."\n\n";
$stringBuilder .= "Your purchase details are recorded as : \n\n";

//if html tags are not to be filtered in the body of email
$stringBuilder .= "<table>" .stripslashes($purchaseinfo) ."</table>";

//otherwise this will be painful to retrieve info out of the html table.
return $stringBuilder;
}
  • 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-14T04:08:29+00:00Added an answer on May 14, 2026 at 4:08 am

    The PHP website has a section on sending mail, example #4 shows how to change your headers to send an HTML formatted email.

    PHP manual on using mail

    Here is the key piece of code you need…

    // 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";
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

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.