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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T19:34:23+00:00 2026-06-06T19:34:23+00:00

I am trying to send email using PHP. The email is an HTML email

  • 0

I am trying to send email using PHP. The email is an HTML email with hundreds of line of HTML code (in file email.html). I don’t want to write the whole HTML code in the PHP. How can I do it? Is my below method correct? Any better alternative?

My Code (PHP):

$email_text = file_get_contents('email.html');
$headers = "From:def@gmail.com";

mail('abc@gmail.com', 'Hello', $email_text, $headers);

My Email File (email.html):

<html>
     <body>
          <a href="http://google.com">Hello</a>
     </body>
</html>

My problem: I want to send an HTML email which will display HTML content. The HTML content is taken from a file called email.html.

Note 1: I have simplified my above code just for the clarity. Original code is having headers which will display HTML code correctly. Also the original HTML file is having hundreds of line and CSS styling. I have mentioned only few lines just to simplify.

Note 2: There are many duplicates of sending email using PHP but I couldn’t find how to include a big HTML file in just one line of PHP code.

  • 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-06T19:34:25+00:00Added an answer on June 6, 2026 at 7:34 pm

    Update for updated question:

    If you don’t want to include all that HTML in your PHP code, then yes file_get_contents() is a fine alternative.


    You need to include the content type, and MIME version in the headers. This is charset UTF-8 also.

    $headers = "From: $from <$from_email>\r\n". 
               "MIME-Version: 1.0" . "\r\n" . 
               "Content-type: text/html; charset=UTF-8" . "\r\n";
    

    http://php.net/manual/en/function.mail.php

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

Sidebar

Related Questions

I am trying to send email using c# following is my code. try {
I am trying to send an HTML email using Perl. open(MAIL,|/usr/sbin/sendmail -t); ## Mail
I'm trying to send an email with an attachment using CakePHP 2.0. The file
I'm trying to accomplish the following, I'm sending a HTML email using PHP Mailer
I am trying to send email using mail() in php. I need the message
i am trying to send email from php i have one php file with
I'm trying to send out a Plain/HTML multipart email out and I'm currently using
Hi there I'm trying to send an HTML email through a PHP webform. The
I'm trying to send email in windows server using PHP. When I use php
I am trying to send an email from PHP using PHPmailer() . I have

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.