I would like to send the message body as HTML. Below I have included the relevant coding. I'm using the following for the message:
$message = '
<html>
<body bgcolor="#FFFFFF">
<b>Project Inquiry: $company</b><br /><br />
<b>Name:</b> $name<br />
<b>Company:</b> $company<br />
</body>
</html>
';
//end of message
I'm using the following headers:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
How can I fix this so it sends as HTML? I tried using EOF but I'm not sure why it's not working either. Any help or guidance is greatly appreciated. Thank you
I think it should work.
Use something like this:
$message = "<html><body bgcolor='#FFFFFF'>";
$message = "<b>Project Inquiry:</b>". $company."<br /><br />";
$message = "<b>Name:</b>". $name."<br />";
$message = "<b>Company:</b>". $company."<br />";
$message = "</body></html>";
Try this post, I posted to show how to send mail in both plain text + HTML version, so that it will even work well for most mail clients too and for browsers it will be HTML mails.
http://stackoverflow.com/questions/22070358/universal-send-email-html-or-plain-text-php/22070726#22070726
Sometimes, the server you are sending mails to, might not allow mails to be sent from local ips..
Related
I want to write a PHP page to run on a cron job to email out the contents of a PHP page.
When trying this, I get the scripts included in the body of the email, not just the echoed out elements.
Here is the script I'm using below currently to try and include kpi.php in the email.
Any thoughts on how I can achieve this?
alternatively I'd be happy to grab a screenshot of the page.
Thanks
<?php
$to = "email#domai.com";
$subject = "Daily Update";
$message = include('kpi.php');
// 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: <no-reply#email.com>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
Just include it beforehand and echo the variables needed into the body of the email
I'm trying to test if the return-path will bounce back on my gmail, but not.
I'm testing to send it to my email (enalds#gmail.com): it works!
And send to unknown email (gifjgogsdkg#fafasfsa.com): it didn't bounce back.
Here's my code
<?php
$message = '
<html>
<head>
<title>Sample Email</title>
</head>
<body>
Sample Email
<br /><br />
Click here to Unsubscribe
</body>
</html>
';
$sender = "enalds#gmail.com";
$email_address = "sender_name#yahoo.com";
$subject = "Testing Email";
$template_name = "Sample Email";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'Return-Path: enalds#gmail.com' . "\r\n";
$headers .= 'From: '.$sender.'' . "\r\n";
if(mail($email_address, $subject, $message, $headers, '-fenalds#gmail.com'))
echo "{$i}. {$email_address} - <span style='color:green'>Successfully</span> Sent [{$template_name}]<br />";
else
echo "{$i}. {$email_address} - <span style='color:green'>Unsuccessfully</span> Sent [{$template_name}]<br />";
You have two solutions to this issue:
First one is leave blank in the php.ini configuration file the "sendmail_from" variable.
This way you could add the additional parameters in the mail function like you have in your code.
The second approach, is set "sendmail_from" in php.ini if you want to have always the same "Return-Path" for every email.
I'm using the php mail function and I have no problem sending the emails, I recieve well the emails on Hotmail and Gmail. But, when I wrote a web address in the message Gmail doesn't accepts the email because it arrives with an hyperlink, even though i'm writing the address in this way: "www.something.com" and I'm using Content-Type: text/plain; on the header.
I've tried to use strip_tags() with the message, but the problem persist.
What can I do?
Please try the code as follow:
<?php
$to = "to_email addrss";
$subject = "Your Subject";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<a href='http://yourlink.com'>http://yourlink.com</a>
</body>
</html>
";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .= 'From: <webmaster#yoursite>' . "\r\n";
mail($to,$subject,$message,$headers);
?>
May be you failed to add content-type:text/html ,while sending your email address. may be this is the reason your anchor link it not working.hope this will work.
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);
?>
I have a php script that sends an email. It looks like this:
<?php
// subject
$subject = "$first_name $last_name has sent you a message on The Red-line";
// message
$message = "<html>
<head>
<title>
The Red-line
</title>
</head>
<body>
<p>
Hi $war_first,
</p> <br />
<p>
$first_name $last_name has sent you a message on the Red-line. To view your message, please login to <a href='www.thered-line.com'>the Red-line.</a>
</p> <br />
<p>
Sincerely,
</p> <br />
<p>
The Red-line Operator
</p>
</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 .= "From: The Red-line messages#theredline.com \r\n";
$headers .= "To: $war_first $last_war <$war_mail>\r\n";
// Mail it
mail($war_mail, $subject, $message, $headers);
?>
When I was testing this out on the remote server, I used this script to send an email to my inbox at turbocapitalist1987#yahoo.com. I got the email but the "from" part doesn't work . Yahoo says that my email was sent from "the#yahoo.com"
Does anybody have a clue as to why this isn't working?
Thanks
For your From header, enclose the actual address with < >:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
This is the correct format to use when you have both a display name and an email address. I'm guessing Yahoo was interpreting the first word "The" as the entire email address, and provided a default (yahoo.com) for the domain.
The <> seems to be your problem, it should be:
$headers .= "From: The Red-line <messages#theredline.com> \r\n";
Secondly, on Unix/Linux, you must have a working MTA (i.e.: sendmail, postfix, etc.) configured on your server, either to relay mail directly, or through a Smart Host. If you're on Windows, you must have a SMTP server configured in php.ini.
I would recommend using pre-built PHP email library such as: http://swiftmailer.org/