Email does not display in HTML format [duplicate] - php

This question already has answers here:
Send HTML in email via PHP
(8 answers)
Closed 7 years ago.
I am using the following code:
$useremail="xxx#gmail.com";
$admin_email="yyy#gmail.com";
$sub="some meassage";
$content=<design with tables>.................;
$reval=mail($useremail,$sub,$content,'From:'. $admin_email));
The code sends the email correctly, but it displays in text format not HTML format which is what I want.
I am using Content-type:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From:'. $admin_email. "\r\n";
$reval=mail($useremail,$sub,$content,$headers);
In this method the email is not delivered.

Try to replace :
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
By :
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
Full code example :
$useremail="xxx#gmail.com";
$admin_email="yyy#gmail.com";
$sub="some meassage";
$content = "Good morning,<br />
<strong>This is an HTML msg sent by php mail.</strong><br />
Thanks :)";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"";
$headers .= 'From:'. $admin_email. "\r\n";
$reval=mail($useremail,$sub,$content,$headers);
if($reval)
{
echo "mail sent";
}
else
{
echo "error.";
}
it's work for me.

Related

PHP fails to send UTF-8 Messages [duplicate]

This question already has answers here:
How to send UTF-8 email?
(3 answers)
Closed 5 years ago.
I have the following PHP code:
<?php
$to = 'info#neatgr.cf';
$subject = date("d/m/Y");
$message = 'Hey 123 !## αβγ';
$headers = "From: testsite < mail#testsite.com >\n";
$headers .= "Cc: testsite < mail#testsite.com >\n";
$headers .= "X-Sender: testsite < mail#testsite.com >\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "X-Priority: 1\n"; // Urgent message!
$headers .= "Return-Path: mail#testsite.com\n"; // Return path for errors
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
mail($to,$subject,$message,$headers);
echo "<script type='text/javascript'>alert('Message sent! We will get back to you soon!');</script>";
echo "<script>window.location.href = 'http://example.com';</script>";
?>
The mail gets sent fine. The problem is that αβγ (Unicode Characters) doesn't get on the mail recipient's end correctly.
This is what the recipient sees: Hey 123 !## αβγ
This is what he should see: Hey 123 !## αβγ
I've looked everywhere and tried everything, changing headers, converting my string to unicode etc. etc., but nothing has worked. Maybe I'm doing something wrong?
Use the UTF-8 charset header, for example:
$headers .= "Content-Type: text/html; charset=iso-8859-1\n";
Goes to:
$headers .= "Content-Type: text/html; charset=UTF-8\n";

HTML content not showing in mail [duplicate]

This question already has answers here:
Send HTML in email via PHP
(8 answers)
Closed 7 years ago.
I had set up email sending in localhost and using that I can access my gmail account to send mail using php script.
<?php
$to = "example#gmail.com";
$subject = "HTML Mail";
$message = "<html><body>";
$message .= "<b>Hey! How are you today?</b>";
$message .= "<br>Regards";
$message .= "</body></html>";
$headers = "From: myemail#gmail.com\r\n";
mail($to,$subject,$message,$headers);
echo "<h1>MAIL SENT</h1>";
?>
When I send this email using this script, it gives out
<html><body><b>Hey! How are you today?</b><br>Regards</body></html>
Why html type output is not shown?
Hey! How are you today?Regards
Like this in gmail?
Could it be that you are missing headers to specify this is HTML content?
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "MIME-Version: 1.0\r\n";
Edit: As pointed by another answer, both headers are needed.
From the PHP documentation 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";
If these headers are missing, the message content is interpreted as plain text.
Hi for sending email with HTML body you need to specify headers. Something like this
//your code <br>
$headers = "From: myemail#gmail.com\r\n"; <br>
//HTML headers <br>
$headers .= 'MIME-Version: 1.0' . "\r\n"; <br>
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
so after that you can send the email with html body
mail($to,$subject,$message,$headers);
good luck

php mail function is not working on online server [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 8 years ago.
i want to send a mail the code is given below. i cant understand waht is happening . It works on localhost but not on live server.
if (isset($_POST['test_mail'])){
$to = '2606ankit#gmail.com'; //put email address on which mail send
$subject = "Newsletter"; //Put subject of mail here
$from = 'ankit#studiokrew.com'; //put email address from
//email body start
// $body .= file_get_contents('file/'.$filename.'');
$body .= 'anio';
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: '.$from. "\r\n";
//if you need to send cc mail then uncomment below line and change email address
//$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$body,$headers);
}
try this..
<?php if (isset($_POST['test_mail'])){
$host=$_SERVER['HTTP_HOST'];
$replyto="<no-reply >";
$to ='2606ankit#gmail.com';
$subject = "Newsletter";
$from = 'ankit#studiokrew.com';
$headers = "From: \"Invoice\"<noreply#$host>\n";
$headers .= "Reply-To: ".$replyto."\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"abc"\"\r\n\r\n";
$headers .= 'From: '.$from. "\r\n";
$header .= "Content-Type:text/html; charset=\"iso-8859-1\"\n";
$body = "This is a multi-part message in MIME format.\r\n";
$body .= "Content-type:text/html; charset=iso-8859-1\r\n";
$body .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$body .= 'anio';
mail($to,$subject,$body,$headers);
}
?>
check the MTA logs on your server.also web server logs the answer will be there somewhere.
Test with a simple mail() script that does not require any external data, just to make sure that your server indeed can send mail. If that fails, you'd have to contact the server admins for help.

mail going in spam folder [duplicate]

This question already has answers here:
PHP mail: All emails are received in the SPAM folder [closed]
(4 answers)
Closed 8 years ago.
this is the mail body header subject and message
$headers = 'MIME-Version: 1.0' . PHP_EOL;
$headers .= "Content-Type: text/html" . PHP_EOL;
$headers .= "From: domin name" . PHP_EOL;
$subject = "1+1 Weekend Bonanza from Pizza Hut";
$message = "";
$message .= '<html>
message body
</html>';
*this is the mail function which i'm using.
mail($to, $subject, $message, $headers);*
My mail always go in the spam folder help me to send it in the inbox as it is very important to send them in the inbox pleae help me out.
Thanks for help in advance.
I'm unable to post the image as my reputation is low. in place of image i have written their is a image.
Email usually arrives to span because of bad headers. Try looking here.
<?php
$headers .= "Organization: Sender Organization\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n"
?>
This additional headers for ur emails might help you
$subject = "1+1 Weekend Bonanza from Pizza Hut";
$header = "from: domin name \r"."<br >";
$header .= "Content-Type: text/html; charset=ISO-8859-1 \r"."<br >";
$header .= "Return-Path: <mail#domainname.com> \r"."<br >";
$header .= "X-Priority: 1 (Highest) \r"."<br >";
$header .= "X-MSMail-Priority: High \r"."<br >";
$header .= "Importance: High \r"."<br >";
$header .= "MIME-Version: 1.0 \r"."<br >";
$message = "<html>
<head>
<meta http-equiv='content-type' content='text/html;charset=UTF-8' />
//Add more here

Problem dynamically sending text message with PHP

I am trying to dynamically send text messages using a PHP script. PHP code:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$textbody=<<<_MESSAGE_
Some text
_MESSAGE_;
mail('myphonenumber#SMSgateway','subject',$textbody,$headers);
I did receive a text message, but it is a "photo message" or rather multimedia instead of text and I am unable to open the message. I have tried playing around with the encoding and $textbody="this text"; instead of *MESSAGE*.
a) How can I send a normal text message (not multimedia)?
b) Why can't I open it?
c) Is there a way for people to respond to the texts I send with text? When I sent myself a text from hotmail I was able to reply and I got the answer in my inbox. When I tried to put $header.= 'From: me <me#somedomain.com>' . "\r\n"; the email wouldn't send
(reason: 553 sorry, your mail was
administratively denied. (#5.7.1))
Thanks!
$sendTo = "test#test.com";
$subject = trim($_POST['subj']);
$headers = "From: ".$_POST['name']."<" . trim($_POST["email"]) .">\r\n";
$headers .= "Reply-To: " . trim($_POST["email"]) . "\r\n";
$headers .= "Return-path: " . trim($_POST["email"]);
$headers .= "\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$message = strip_tags($_POST["messg"]);
if (#mail($sendTo, $subject, $message, $headers))
{ echo "sent successfully"; }
else
{ echo "Error ... Plz try again later" ; }
This code which I'm using to send emails
I worked before on SMS project so if you have any question about how to link with Getaway feel free to contact me

Categories