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.

[code]$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();

Only cool people share!

mail($to, $subject, $message, $headers);[/code]

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.

[code]// 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);[/code]

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.

[code]
<?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>[/code]

PHP HTML Script For Emails was last modified: December 22nd, 2015 by Maximus Mccullough
Summary
PHP HTML Script For Emails
Article Name
PHP HTML Script For Emails
Description
Learn how to create PHP HTML Script For Emails. This is a free tutorial on how to use PHP to send HTML rich emails. Click here now!
Author
php-html-email-script

Leave a Reply

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