Send HTML in email via PHP
It is pretty simple. Leave the images on the server and send the PHP + CSS to them...
$to = 'bob@example.com';
$subject = 'Website Change Request';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);
It is this line that tells the mailer and the recipient that the email contains (hopefully) well-formed HTML that it will need to interpret:
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
Here is the link I got the information from... (link)
You will need security though...
Sending HTML Email via PHP with Variables and External HTML Template
A better approach would be to just include the file and use ob_get_clean()
:
ob_start();
if($_POST['service']=="Service 1") {include 'email_template-service-1.php';}
else include 'email_template-service-2.php';
$message = ob_get_clean();
Anything echoed between ob_start()
and $message = ob_get_clean()
will go into the $message
variable.
Php mail: how to send html?
use this header for the mail:
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
and for the content/body:
<html>
<head>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
... ... ...
it's important to use inline css commands and recommanded to use tables for the interface.
...
In your Mail-Body you than have to put HTML code with head and body
Send HTML email with php?
You need to send full headers with content type, not just mail_from. Heres an example
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= $mail_From . "\r\n";
mail($mail_To,$mail_Subject,$mail_Body,$headers);
http://www.w3schools.com/php/func_mail_mail.asp
In your code:
$mail_From = $From_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;
mail($mail_To, $mail_Subject, $mail_Body, $mail_From);
The $mail_From is the fourth parameter (headers). Create a new string that contains full headers for html email plus: $_From
$mail_From = $From_email;
$mail_To = $payer_email;
$mail_Subject = $Subject_line;
$mail_Body = $email_msg;
//start $headers
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n"; //adds content type to headers
$headers .= $mail_From . "\r\n"; //adds the sender details
mail($mail_To,$mail_Subject,$mail_Body,$headers); //sends the email
If you echo $headers it will be something like this
MIME-Version:1.0
Content-type:text/html;charset=iso-8859-1
From:email@email.com
Send HTML Email With Attachments PHP
Actually I wanted to share this code snippet with community, I thought if I click on Answer your question, this question will get posted just as a topic. But let it be,
I hope other users might find it useful.
send html email from php
You need to add content-type
as html
in your email header as like this :
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: '.$from."\r\n".
'Reply-To: '.$from."\r\n" .
'X-Mailer: PHP/' . phpversion();
How to send HTML-formatted message with standard mail function in PHP
Php Html email
<?php
$to = "abc@gmail.com";
$subject = "PUT_SUBJECT_HERE";
$mail_body = '<html>
<body bgcolor="#573A28" topmargin="25">
Put HTML content here with variables from PHP if you like
Variable display Example: ' . $subject . '
<h1>this is a heading</h1>
</body>
</html>';
//$headers = "From: abc@gmail.com";
//$headers .= "Content-type: text/html";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
// More headers
$headers .= 'From: <abc@gmail.com>' . "\r\n";
mail($to, $subject, $mail_body, $headers);
?>
Enjoy this code
Related Topics
Is There a Function to Extract a 'Column' from an Array in PHP
Simplest PHP Example For Retrieving User_Timeline With Twitter API Version 1.1
Startswith() and Endswith() Functions in PHP
Matching Unicode Letter Characters in Pcre/PHP
Only Variables Should Be Passed by Reference
What Are the PHP Operators "" and ":" Called and What Do They Do
Redirect All to Index.PHP Using Htaccess
Why Can't I Access Datetime-≫Date in PHP'S Datetime Class
PHP Preg_Match With Working Regex
Difference Between Public, Private, and Protected
What Is the Most Accurate Way to Retrieve a User'S Correct Ip Address in PHP
MySQL Query to Get Column Names
PHP Fatal Error: Using $This When Not in Object Context
Do Htmlspecialchars and MySQL_Real_Escape_String Keep My PHP Code Safe from Injection