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

  • Home
  • SEARCH
  • 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 8161223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T18:27:11+00:00 2026-06-06T18:27:11+00:00

I have to written the following code to send a mail using PHP in

  • 0

I have to written the following code to send a mail using PHP in my website, which is hosted on a Linux server. The mail is sent, but the message is sent as raw HTML instead of markup text. Here’s the code:

<?php
sendMail('name@domain.tld', 'Your recovered password', 'Your password is <b>ABC123</b>', 'kush.impetus@gmail.com');

function sendMail($from='name@domain.tld', $subject, $message, $to = 'name@domain.tld'){
    $message = '<html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
            <title>'.$subject.'</title>
        </head>
        <body>'.$message.'</body>
        </html>';
    $message = preg_replace("#(?<!\r)\n#si", "\r\n", $message); 
    $message = wordwrap($message, 70);  

    $headers   = array();
    $headers[] = "MIME-Version: 1.0";
    $headers[] = "Content-type: text/plain; charset=UTF-8";
    $headers[] = "From: $from";
    $headers[] = "Reply-To: $from";
    $headers[] = "Subject: {$subject}";

    $additional_params = "-f $from -r $from";

    if(mail($to, $subject, $message, implode("\r\n", $headers)))
        echo 'Mail Sent';
    else
        echo 'Mail NOT Sent';
    exit();
}

?>

How do I correct the code to send the HTML mail correctly?

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-06T18:27:12+00:00Added an answer on June 6, 2026 at 6:27 pm

    Change this line

    $headers[] = "Content-type: text/plain; charset=UTF-8";
    

    to

    $headers[] = "Content-type: text/html; charset=UTF-8";
    

    This way you tell your mail program that it’s HTML and not a plain text.

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

Sidebar

Related Questions

I have written the following code. But it is removing only &nbsp; not <br>
I have recently written some code which schedules messages to send to one of
I have written the following code in the server side for a chat client
I have written following code for the client of RMI. But getting java.rmi.ConnectException: Connection
I have written some code in my VB.NET application to send an HTML e-mail
I have written ASP.Net code to send mails from domain1.com mail account such as
I have written following code to attach gesture recogniser to multiple imageviews. [imageview1 setUserInteractionEnabled:YES];
I am trying my hands on WPF MVVM. I have written following code in
I have written a following code to get just the file name without extension
I have written the following code choice /m Do you want to add another

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.