My script send the email but it doesn't render the html tags. I'm not sure why not.
$email = $row['email'];
$mail_body = '<html>
<body>
<p>hello,'.$name.'</p>
<p>this is a testing email </p>
<hr />
<p>by server</p>
</body>
</html>';
$subject = "Better website";
$to = "$email";
$headers = "From: mailscript#hotmail.com\r\n";
$headers .= "Content-Type: text/html\r\n";
$mail_result = mail($to, $subject, $mail_body, $headers);
Try setting the mime type as well as shown in the manual for mail()
// 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";
as Jrod already answered you need to add the header
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
but I found that this one is screwing mine up as of late and had to comment it out:
$headers = 'MIME-Version: 1.0' . "\r\n";
Related
My mail function is working fine, delivering mail after filling the form.
But the output in the mail is with HTML tags as shown attached.
Here is my code.
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
mail($admin_email, "$subject", $comment, "From:" . $email);
echo "Thank you for contacting us!";
}
?>
How can i get Output like this.
Location : Hyderabad
No of Bags : 50
Use the below Headers to send email with HTML tags:
// 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";
Updated Code:
<php if (isset($_REQUEST['email'])) {
$admin_email = "abcdef#gmail.com";
$email = $_REQUEST['email'];
$subject = $_REQUEST['salespersonname'];
$location = $_REQUEST['location'];
$noofbags = $_REQUEST['noofbags'];
$print = '<div>Location : $location<br />No of Bags : $noofbags</div>';
$comment = $print;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
echo "Thank you for contacting us!";
}
?>
Hope this will be help.
you have to set header's
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
mail($to, $subject, $message, $headers);
Add following headers :
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
Pass $headers as 4th parameter in mail function.
You need to set the Content-type header in your email message:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and pass into
mail($admin_email, "$subject", $comment, "From:" . $email, $headers);
Your message body also needs to be contained in <html> tags.
I have the following issue when using php mail, I'll expose the two ways I do it and wich result I get and expect:
Case 1:
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
The email i sent and the html decoded in the correct way, but my "From" header looks like: "noreply#124512.net" (Strange root).
Case 2:
$to = $EmailsPropiosPresupuestos;
$subject = $txtAsuntoCliente;
$message = $emailCliente;
$headers .= "From: noreply#example.com\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
Now my "From" header is fine, "noreply#example.com", but the mail doesn't decode the html, so I can't view the message in the correct way.
Try to add the MIME version to your header:
$headers .= "MIME-Version: 1.0\n";
For the no-reply I suggest you to add it using the Reply-To:
$headers .= "Reply-To: noreply#example.com\n";
This will allow you to keep a better from email address.
And In my code I use \n on each header line and finish with \r\n.
from: http://de3.php.net/manual/en/function.mail.php
Example #4 Sending HTML email
It is also possible to send HTML email with mail().
<?php
// multiple recipients
$to = 'aidan#example.com' . ', '; // note the comma
$to .= 'wez#example.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '
<html>
<head>
<title>Birthday Reminders for August</title>
</head>
<body>
<p>Here are the birthdays upcoming in August!</p>
<table>
<tr>
<th>Person</th><th>Day</th><th>Month</th><th>Year</th>
</tr>
<tr>
<td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
</tr>
<tr>
<td>Sally</td><td>17th</td><td>August</td><td>1973</td>
</tr>
</table>
</body>
</html>
';
// 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: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
?>
I am attempting to send an email using the mail() PHP function. I had it working until I attempted to give it a subject of "User registration", then the mail is not sent!
Heres the code (have simplified it greatly)
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'From: noreply#example.com' . "\r\n" ;
$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
$headers .= 'From: Website <admin#example.com>';
mail($to, 'User Registration', $message, $headers);
I also attempted to use a variable containing the string of text but that didnt work.
Why is it not sending the mail when I add the subject exception?
Thanks
EDIT: updated code thats still not working
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: Website <admin#example.com>';
mail($to, 'User Registration', $message, $headers);
On your 4th line you're using ' that handles everything inside of it as a string so change
$headers .= 'Content-type: text/html; chareset=iso-8859-1\r\n';
To:
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
and as mentioned in the comments change chareset to charset
Edit:
if your sending a txt/html mail you have according to documentation to set mime in the headers too so try this
$to = $this->post_data['register-email'];
$message = 'Hello etc';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
$headers .= 'From: Website <admin#example.com>' . "\r\n";
mail($to, 'User Registration', $message, $headers);
If it still doesn't work you could try to debugg your code, simply add
error_reporting(E_ALL);
ini_set('display_errors', '1');
on top of the page, and take it from there, and if you still can't solve it by yourself post it here and I'll do my best to help ya out.
I'm using this code on most of my projects:
$subject = 'subject';
$message = 'message';
$to = 'user#gmail.com';
$type = 'plain'; // or HTML
$charset = 'utf-8';
$mail = 'no-reply#'.str_replace('www.', '', $_SERVER['SERVER_NAME']);
$uniqid = md5(uniqid(time()));
$headers = 'From: '.$mail."\n";
$headers .= 'Reply-to: '.$mail."\n";
$headers .= 'Return-Path: '.$mail."\n";
$headers .= 'Message-ID: <'.$uniqid.'#'.$_SERVER['SERVER_NAME'].">\n";
$headers .= 'MIME-Version: 1.0'."\n";
$headers .= 'Date: '.gmdate('D, d M Y H:i:s', time())."\n";
$headers .= 'X-Priority: 3'."\n";
$headers .= 'X-MSMail-Priority: Normal'."\n";
$headers .= 'Content-Type: multipart/mixed;boundary="----------'.$uniqid.'"'."\n";
$headers .= '------------'.$uniqid."\n";
$headers .= 'Content-type: text/'.$type.';charset='.$charset.''."\n";
$headers .= 'Content-transfer-encoding: 7bit';
mail($to, $subject, $message, $headers);
I would suggest to use PHP_EOL instead of \r\n or \n as the line break would then be determined by your environment...
$headers = 'MIME-Version: 1.0' . PHP_EOL;
etc.. hoping this might finally solve your problem!
I am trying to send style information along with an email via PHP mail() function. Unfortunately, even though my mail client is set to accept styled emails it still just renders as plain html text.
$to = $email;
$subject = "Subject Details";
$message='<html><body><table width="600" height="840" border="0" cellpadding="5" cellspacing="5">';
$message.='<tr><td height="110"><img src="https://user.co.uk/images/logo.jpg" alt="SignDox" width="300" height="100" /></td></tr>';
$message.='<tr><td height="29" bgcolor="#5C1561"> </td></tr>';
$message.='<tr><td height="537" valign="top">';
$message.="Message Goes Here\n\n";
$message.="Username: ".$new_agent_id."\n";
$message.="Password: ".$pass1."\n\n";
$message.="To sign in to your user panel follow this link: \n";
$message.="Inside your admin section you will be able to change your username and password.\n";
$message.='</td></tr>';
$message.='<tr><td height="140" bgcolor="#5C1561"> </td></tr></table></body></html>';
$from = "no-reply#sender.co.uk";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
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";
Note:
1) If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package ยป PEAR::Mail_Mime.
2) It is worth noting that the mail() function is not suitable for larger volumes of email in a loop. This function opens and closes an SMTP socket for each email, which is not very efficient.
Please read more this: PHP Manual
You need to define the correct headers in order to send HTML formatted emails. This can be done very simply using:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
However, I would urge you to use the PHPMailer Class. This class will handle all headers and anything else you may need. You can easily add attachments, embed images, send via SMTP etc...
It is a fantastic class, and not to mention the amount you will learn with objects and classes, expecially if you are a newbie to PHP :-)
See here for the PHPMailer Class
Set the content type, and charset as desired. You should also terminate your from header with \r\n.
$headers = "From:" . $from . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
try something like
<?php
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=iso-8859-1";
$headers[] = "From:" . $from;
/*
$headers[] = "Bcc: JJ Chong <bcc#domain2.com>";
$headers[] = "Subject: {$subject}"; */ optional
mail($to, $subject, $message, implode("\r\n", $headers));
function send_mail($from,$fromName,$to,$object,$bodyText,$bodyHtml){
$site = "mywebsite.ca";
$from = $fromName." <".$from.">";
$limite = "_----------=_parties_".md5(uniqid (rand()));
$header = "Reply-to: ".$from."\n";
$header .= "From: ".$from."\n";
$header .= "X-Sender: <".$site.">\n";
$header .= "X-Mailer: PHP\n";
$header .= "X-auth-smtp-user: ".$from." \n";
$header .= "X-abuse-contact: ".$from." \n";
$header .= "Date: ".date("D, j M Y G:i:s O")."\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/alternative; boundary=\"".$limite."\"";
$message = "";
$message .= "--".$limite."\n";
$message .= "Content-Type: text/plain\n";
$message .= "charset=\"iso-8859-1\"\n";
$message .= "Content-Transfer-Encoding: 8bit\n\n";
$message .= $bodyText;
$message .= "\n\n--".$limite."\n";
$message .= "Content-Type: text/html; ";
$message .= "charset=\"iso-8859-1\"; ";
$message .= "Content-Transfer-Encoding: 8bit;\n\n";
$message .= $bodyHtml;
$message .= "\n--".$limite."--";
if(mail($to,$object,$message,$header)){
//echo all
}
else{
//echo mssage not submit
}
}
hope this function can help you. try to use this function to as your send_mail, then at the buttom try to
write a condition to see if your message is submitted.You just needed to give inputs in it
//your header should be like this
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
I have PHP and Postfix set up at my Ubuntu server. I need to send HTML email from PHP script. The email is sent just fine, but it is displayed as plain text with HTML tags included. Additionally, some headers are also displayed in the email itself.
My guess is, that it has something to do with the headers. I've spent nearly a day searching for a possible solution and haven't found one.
Here's the PHP code:
$headers='';
$headers.="MIME-Version: 1.0 \r\n";
$headers.="Content-type: text/html; charset=\"UTF-8\" \r\n";
$headers.="From: ".FROM_EMAIL."\r\n";
mail($email, $vars['title'], $content, $headers);
EDIT:
$headers='';
$headers.='MIME-Version: 1.0'."\r\n";
$headers.='Content-type: text/html; charset=iso-8859-1'."\r\n";
$headers.='From: Kinesioteip.ee<'.FROM_EMAIL.'>'."\r\n";
$headers.='To: '.$email."\r\n";
mail($email, $vars['title'], $content, $headers);
Still no luck...
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To:' . "\r\n";
$headers .= 'From: Admin<youremail#email.com>' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
can you try changing these lines
$headers.="MIME-Version: 1.0 \r\n";
$headers.="Content-type: text/html; charset=\"UTF-8\" \r\n";
to
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
and see if they work
i think your fourth header is wrong because FROM_EMAIL variable not having '$'
try
$headers.="From: ".$FROM_EMAIL."\r\n";
$vars['title'] change in to $var
mail($email, $vars, $content, $headers);