I have a contact form and want to format the output email in HTML and use charset utf-8 as I need some special character. I have following code, but it's not working.
Edit: The email is sent, but without html and utf-8.
<?php
if ($_POST["email"]<>'') {
$ToEmail = 'contact#domain.com';
$EmailSubject = 'Email Subject';
$mailheader = 'From: donotreply#domain.com' . "\r\n" .
'Reply-To:' .$_POST["email"]. "\r\n" .
'X-Mailer: PHP/' . phpversion();
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/html; charset=utf-8'."\r\n".
$MESSAGE_BODY .= "<b>Navn:</b> ".$_POST["name"]."\r\n";
$MESSAGE_BODY .= "<b>Telefon:</b> ".$_POST["telephone"]."\r\n";
$MESSAGE_BODY .= "<b>Email:</b> ".$_POST["email"]."\r\n\r\n";
$MESSAGE_BODY .= "".nl2br($_POST["message"])."\r\n";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
Try changing header from
$headers .= "Content-Type: text/html; charset=UTF-8\r\n";
to
$headers .= "Content-Type: text/html; charset=iso-8859-1\r\n";
Its better use PHPMailer This will allow you to send mails via a SMTP server
I found that the only thing that was wrong was the order of the code. By moving 'X-Mailer: PHP/' . phpversion(); below Content-Type the mail is encoded correct.
This is how I fixed it:
$mailheader = 'From: donotreply#domain.com' . "\r\n" .
'Reply-To:' .$_POST["email"]. "\r\n" .
'MIME-Version: 1.0'."\r\n".
'Content-Type: text/html; charset=utf-8'."\r\n".
'X-Mailer: PHP/' . phpversion();
Related
I can't send html email through PHP.
in yahoo email, it is showing text based email. How can i make email to show normal html based.
Output of my email in yahoo mail:
<html><head></head><body><h2>test heading</h2><br><table><tr><td>Color / Pattern: </td><td>yellow</td></tr></table></body></table>
PHP code:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: '.$email."\r\n".
'Reply-To: '.$reply_to."\r\n" .
'X-Mailer: PHP/' . phpversion();
$message = "<html><head></head><body><h2>test heading</h2><br><table><tr><td>Color / Pattern: </td><td>yellow</td></tr></table></body></table>";
mail($mail_to, $subject, $message, $header);
I am sending email through PHP and I want to change the "sent by" email in the headers:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: test#test.com' . "\r\n";
$headers .= 'Reply-To: test#test.com' . "\r\n" .'X-Mailer: PHP/' . phpversion();
I am also attaching the image for reference:
I want to change the highlighted email address. Thanks in advance
This question already has answers here:
Php mail: how to send html?
(5 answers)
Closed 9 years ago.
I have the following php code:
<?php
header('Content-Type: text/html; charset=utf-8');
if (isset($_POST['email']))
//if "email" is filled out, send email
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="<html><body>
<span style='background-color: #cdcdcd'>
text: $name
</span>
text: $phone
<span style='background-color: #cdcdcd'>
text: $email
</span>
text: $message </html><body/>";
$recipient = "email#email.com";
$subject = "text text text ";
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($recipient, $subject, $formcontent, $headers) or die("Error!");
echo "Thank You!";
?>
The problem is that wehn I recieve the email I see all the HTML tags in the email body, and the email isn't styling.
My question is how can I fix it?
You're not actually setting the Content-type header in the email headers variable
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
"X-Mailer: PHP/" . phpversion() . "\r\n" .
"Content-Type: text/html; charset=utf-8";
Also go for exclusively single quotes, or double quotes when concatenating strings
You need $headers for text/html not header('Content-Type: text/html; charset=utf-8');
If you don't get a better answer, I'll improve mine later. Short on time at the moment.
Try it -
Remove line
header('Content-Type: text/html; charset=utf-8');
and replace
$headers = "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
by
$headers = "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
$headers .= "From: $email" . "\r\n" .
"Reply-To: $email" . "\r\n" .
'X-Mailer: PHP/' . phpversion();
I am sending email using php script and i am setting from address as
$headers = "MIME-Version: 1.0" . "$from" . "\r\n";
$headers.= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
So, the mail coming to my mail address as from support#mysite.com, But i need to set from address as support#gmail.com.But it is not coming with the modified from address. So, please help to solve this problem..
You try this...
<?php
$to = 'nobody#example.com';
$subject = 'Mail Subject';
$message = 'Test';
$headers = 'From: support#gmail.com' . "\r\n" .
'Reply-To: support#gmail.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>
Hop this will works...
Replace header text,
$headers = 'MIME-Version: 1.0' . "\r\n" . 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= "X-Mailer: PHP \r\n";
$headers .= "From: YourName <support#gmail.com>";
To get more information about mail function
may this help you.
I am new to PHP and send an email using following code
<?php
$to = 'to#xyz.com';
$subject = 'the subject';
$message = '<table dir="rtl"><tr><td>'. "\r\n";
$message .= '<b>This is Bold</b></br> <i> This is Italics</i></br>شطب 14 مرشحا لمجلس الأمة الكويتي'. "\r\n";
$message .= '</td></tr></table>';
//Headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=UTF-8' . "\r\n";
$headers .= 'Content-Transfer-Encoding: quoted-printable' . "\r\n" .
$headers .= 'From: from#xyz.com' . "\r\n";
$headers .= 'Reply-To: replyto#xyz.com' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
ini_set ( "SMTP", "smtp.xyz.com" );
mail($to, $subject, $message, $headers);
?>
I can receive the email and it display the arabic also but it also show the from email address in the body of the email.
And other issue is that arabic is RTL even after mentioning in table dir-"RTL" it still show the message as LTR.
Example of Email Received
from#xyz.com
This is Bold
This is Italics
شطب 14 مرشحا لمجلس الأمة الكويتي
You could try using the alternative of CSS2 style:
style="direction:RTL; unicode-bidi:embed;"
Extra reading: http://www.i18nguy.com/markup/right-to-left.html