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...
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 links in php mail message
I've checked with your code..
Seems like you are making a simple mistake..
You are not concatenating your code.. you are re assigning your header at line 3
Your Code
$emailid = $_POST['email'];
$phoneno = $_POST['phoneno'];
$to = "demoemail@gmail.com"; // this is your Email address
$from = $emailid; // this is the sender's Email address
$subject = "Intrested in scheduling appointment.";
$message = "<a href='http://www.google.com'>Click Here</a>";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers = "From:" . $from;
$retval = mail($to,$subject,$message,$headers);
Updated Code on headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From:" . $from;
Update your header and try again!
Thanks! Have a nice day!
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
Adding style to a php html email
You need to use inline style to get it works on your email
$to = $newsletter_email;
$subject = 'Thank you for subscribing';
$message = '
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<div id="email-wrap" style='background: #151515;color: #FFF;'>
<p>Hi,</p><br>
<p>Thank you.</p><br>
<p>Thank you,</p>
<p>Administration</p>
</div>
</body>
</html>
';
$from = "newsletter@example.com";
//$Bcc = "example@example.com";
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: ' .$to. "\r\n";
$headers .= 'From: ' .$from. "\r\n";
// $headers .= 'Bcc: '.$Bcc. "\r\n";
// Send the email
mail($to,$subject,$message,$headers);
For the second part of your question you can use something like this
$to = 'test@server.com';
$email_from = "best.buy@yahoo.com";
$full_name = 'Best Buy';
$from_mail = $full_name.'<'.$email_from.'>';
$from = $from_mail;
$headers = "" .
"Reply-To:" . $from . "\r\n" .
"X-Mailer: PHP/" . phpversion();
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: ' . $from_email . "\r\n";
mail($to,$subject,$message,$headers);
Send HTML Form using SMTP
We only managed to fix our issue by sending it via SMTP but we have to install PHPmailer first on cPanel using the following command
composer require phpmailer/phpmailer
Instructions: https://muftsabazaar.com/blog/post/how-to-install-the-phpmailer-in-cpanel
Then we updated our PHP code as below
<?php
use phpmailer\phpmailer\PHPMailer;
use phpmailer\phpmailer\Exception;
require '/home/rentersshield/vendor/phpmailer/phpmailer/src/Exception.php';
require '/home/rentersshield/vendor/phpmailer/phpmailer/src/PHPMailer.php';
require '/home/rentersshield/vendor/phpmailer/phpmailer/src/SMTP.php';
// Instantiation and passing [ICODE]true[/ICODE] enables exceptions
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'example@domain.com'; // SMTP username
$mail->Password = 'emailpass'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, [ICODE]ssl[/ICODE] also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('example@domain.com', 'New Form submission on Rentersshield Website');
$mail->addAddress('example@domain.com', 'JohnUser'); // Add a recipient
$mail->addAddress('example@domain.com'); // Name is optional
$mail->addReplyTo('example@domain.com', 'Information');
$mail->addCC('example@domain.com');
$mail->addBCC('example@domain.com');
$feedback_page = "feedback_form.html";
$error_page = "error_message.html";
$thankyou_page = "https://rentersshield.org/success/";
// Content
$first_name = $_REQUEST['first_name'] ;
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Here is the subject';
$mail->Body =
"First Name: " . $first_name . "\r\n" ;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
header( "Location: $thankyou_page" );
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
Related Topics
How to Resolve Curl Error (7): Couldn't Connect to Host
Can HTML Be Embedded Inside PHP "If" Statement
How to Call a MySQL Stored Procedure from Within PHP Code
The MySQLi Extension Is Missing. Please Check Your PHP Configuration
Execute PHP Scripts Within Node.Js Web Server
PHP: Utilizing Exit(); or Die(); After Header("Location: ");
$_Post Vs. $_Server['Request_Method'] == 'Post'
Use PHP to Convert Png to Jpg With Compression
MySQLi Fetch_All() Not a Valid Function
Difference Between If () { } and If (): Endif;
Downloading Large Files Reliably in PHP
Including a Remote File in PHP
Are There Good Tutorials on How to Use Pdo
Is the Leading Colon For Parameter Names Passed to Pdostatement::Bindparam() Optional