Add HTML formatting in phpmailer
By default, the PHP mail()
function is text/plain
.
In your mail()
headers, change the content-type
to text/html
and try.
Example:
<?php
$body = "<html>\n";
$body .= "<body style=\"font-family:Verdana, Verdana, Geneva, sans-serif; font-size:12px; color:#666666;\">\n";
$body = $message;
$body .= "</body>\n";
$body .= "</html>\n";
$headers = "From: My site<noreply@example.com>\r\n";
$headers .= "Reply-To: info@example.com\r\n";
$headers .= "Return-Path: info@example.com\r\n";
$headers .= "X-Mailer: Drupal\n";
$headers .= 'MIME-Version: 1.0' . "\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
return mail($recipient, $subject, $message, $headers);
?>
PHP Mailer:
You need to set IsHTML(true)
:
$mail->IsHTML(true);
PHPmailer sending HTML CODE
Calling the isHTML()
method after the instance Body
property (I mean $mail->Body
) has been set solved the problem for me:
$mail->Subject = $Subject;
$mail->Body = $Body;
$mail->IsHTML(true); // <=== call IsHTML() after $mail->Body has been set.
Sending information from an HTML page with PHP Mailer
Bonjour Seazy. This won't work:
$mail->MsgHTML($_POST['name']);
$mail->MsgHTML($_POST['prenom']);
$mail->MsgHTML($_POST['email']);
$mail->MsgHTML($_POST['message']);
You will end up with a message that contains only what's in the message
field, and msgHTML
, won't be much help here. Keeping it simple, you need to do something like this (using a plain-text message):
$mail->Body = <<<EOT
{$_POST['name']}
{$_POST['prenom']}
{$_POST['email'])}
{$_POST['message']}
EOT;
It looks like you've based your code on a very old example, so take a look at the contact form example provided with PHPMailer.
If you instead want to include these values in a template, you need to look at loading those template files using PHP's output buffering and include
statement, along the lines of:
ob_start();
include 'template.php';
$html = ob_get_contents();
ob_end_clean();
$mail->msgHTML($html);
PHPMailer - HTML Formatting Issue
If you want to declare a string variable using single quotes, you just have to concatenate variables this way:
$htmlBody = '<html>
<head><title>Online Order Form</title></head><body>
<p><b>Account Name:</b> '.$AccountName.'<br>
<b>Delivery To:</b> '.$DeliveryTo.'<br>
<b>Order No:</b> '.$OrderNo.'<br>
<b>Del Date:</b> '.$DelDate.'<br>
<b>Builder Name:</b> '.$BuilderName.'<br>
<b>Delivery Instructions:</b> '.$DeliveryInstructions.'<br>
<b>Contact Phone:</b> '.$ContactPhone.'<br>
...
';
Otherwise you must declare your string variable using a double quotes if you want variables replaced by their values:
$htmlBody = "<html>
<head><title>Online Order Form</title></head><body>
<p><b>Account Name:</b> $AccountName<br>
<b>Delivery To:</b> $DeliveryTo<br>
<b>Order No:</b> $OrderNo<br>
<b>Del Date:</b> $DelDate<br>
<b>Builder Name:</b> $BuilderName<br>
<b>Delivery Instructions:</b> $DeliveryInstructions<br>
<b>Contact Phone:</b> $ContactPhone<br>
...
";
phpmailer body, want to use html and php
Setting Debugoutput
has nothing to do with sending HTML - it's the error output format. You need to call isHTML()
or set your content using msgHTML()
. Also there is no such word as 'verificate' it's just 'verify'.
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 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...
Related Topics
How to Retrieve the Visitor's Isp Through PHP
PHP 5 Reflection API Performance
How to Capture Search Term from Google Search
JSON: PHP to JavaScript Safe or Not
PHP Send Email with Attachment
Laravel Many to Many Self Referencing Table Only Works One Way
How to Disable Mod_Security in .Htaccess File
Laravel Orm from Self Referencing Table Get N Level Hierarchy JSON
Stdclass Object and Foreach Loops
Change Database Connection in Laravel Model
Boolean Variables Posted Through Ajax Being Treated as Strings in Server Side
Send a JSON Object from Android to PHP Server with Post Method and Httpurlconnection