1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 5.00 out of 5)

PHP HTML Script For Emails

If you are looking for PHP HTML script for emails you have come to the right place. If you look at our PHP Snippets for email. You may be disappointed that when you send an email that you do not actually see formatted HTML.

PHP Header For HTML Email *

Emails do not automatically display HTML. This is a security measure that implemented years ago. however as more security features advance we safely open HTML emails. You still want to make sure that it is coming from a trusted source before opening the email.

Plain Text Email Code for PHP *

If you want to send plain text email to people you would use a code that looks like this. It will not give you a very good looking email. On the other hand a visitor will not get any warnings in their email either. Plain text email are pretty much a thing of the past even if people hate them.

$to = $email;
$subject = 'Service Schedule Confirmation';
$message = 'Hello';
$message .= ' message goes here ';
$headers = 'From: you@yourwebsite.com' . "\r\n" .
'Reply-To: noreply@yourwebsite.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

HTML PHP Email Script *

If you want a script that will put HTML in the email use the following code. Notice that we are sending headers with the email. These headers set the mime type. It also declares that the email should use HTML in its content. Finally we use the mail() function in php to do the actual sending of the email.

// Set the content-type to HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";

// From and CC people
$headers .= 'From: <you@yourwebsite.com>' . "\r\n";
$headers .= 'Cc: soneoneelse@theirwebsite.com' . "\r\n";

mail($to,$subject,$message,$headers);

Complete Code Example of Sending PHP HTML Emails *

If you upload this script to your server you will be able to send an HTML email.

<?php 
if(isset($_POST['submit'])){
$to=$_POST['email'];
$subject=$_POST['subject'];
$message=$_POST['message'];

$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <you@yourwebsite.com>' . "\r\n";
$headers .= 'Cc: soneoneelse@theirwebsite.com' . "\r\n";

mail($to,$subject,$message,$headers);
}
 ?></pre>
<form action="" method="post"><input name="subject" type="text" placeholder="Subject" />
<textarea name="message" placeholder="put message here"></textarea> <input name="submit" type="submit" value="submit" /></form>
<pre>
PHP HTML Script For Emails was last modified: December 22nd, 2015 by Maximus Mccullough

php-html-email-script

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.