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: [email protected]’ . "\r\n" .
‘Reply-To: [email protected]’ . "\r\n" .
‘X-Mailer: PHP/’ . phpversion();
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";
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.
<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>