HTML content not showing in mail [duplicate] - php

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

Related

Email does not display in HTML format [duplicate]

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.

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.

HTML tags in php email [duplicate]

This question already has answers here:
PHP: Html send email in html format
(2 answers)
Closed 8 years ago.
I want to send email in php with some HTML.
In my email, it's giving me like,
Hello <strong>,</strong><br><br>
It's not basically parse HTML code. Instead of effect, it's printing html tags.
This is my email function:
mail("$user_email","ESubject","$message","From: Name");
Message variable:
$message = "Hello <strong>,</strong><br><br>
To verify your email and complete your registration please click on the link below: <br /><br />
<a href='<?=$link?>'>VERIFY ACCOUNT</a>";
You need to set the Content type : text/html on your header !
// 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";
and add it to your mail()
mail($to, $subject, $message, $headers); //<--- Like that.
Note:
If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package ยป PEAR::Mail_Mime.
Source : PHP.net
EDIT :
Just do it this way
$message = "Hello <strong>,</strong><br><br>
To verify your email and complete your registration please click on the link below: <br /><br />
<a href=$link>VERIFY ACCOUNT</a>";
For better understanding please refer below script:
<?php
$to = "somebody#example.com, somebodyelse#example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>Hello <strong>,</strong><br><br>
</body>
</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: <webmaster#example.com>' . "\r\n";
$headers .= 'Cc: myboss#example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>

HTML email just shows as Code [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Sending HTML email from PHP
Using PHP to send an email.
I want it to be HTML based but when I get the email in my inbox it just shows the raw code.
How can I make it interprited as HTML rather then just text?!
For everyone asking to see the code
<?php
//The email of the sender
$email = $_POST['email'];
//The message of the sender
$message = "<html></html>";
//The subject of the email
$subject = "Fanshawe Student Success";
$extra = $email."\r\nReply-To: ".$email."\r\n";
mail($email,$subject,$message,$extra);
?>
from the docs: http://php.net/manual/en/function.mail.php
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
obviously $headers has to be passed to the mail
here you go:
// multiple recipients
$to = 'someemail#address.com';
//subject
$subject = 'Email Template for Lazy People';
//message body
$message = "
<html>
<head>
<title>My Title</title>
</head>
<body>
<div>
<b>My email body</b>
</div>
</body>
</html>
";
//add headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: yourself<info#yourself.com>' . "\r\n";
$headers .= 'From: myself<info#myself.com>' . "\r\n";
//send mail
mail($to, $subject, $message, $headers);

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