On sending a mail I've set my header to:
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
$headers .= "Content-Type: text/html; charset=UTF-8\n";
for mail($to, $subject, $message, $headers);
The Tómas is working in the content correctly but not in the from section of the email. It shows up like Tómas. Any idea how to modify the header to make this work?
Many thanks.
Tó = Tó
change the following line
$headers = 'From: Tómas<tomas#email.com>'. "\r\n";
with
$headers = 'From: Tomas<tomas#email.com>' . "\r\n";
Related
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!
When I added "a href tag " in the mail body the mail is not sent.
If I remove this 'a href and www' tag, the mail sends and all other content display as per my requirement.
I don't know where is the exact problem, I'm using GoDaddy hosting with PHP 5.3 version.
If anyone has a better solutions please share with me .
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<a href=www.google.com>Click here</a>';
// To send HTML `enter code here`mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
// Additional headers
$headers .= 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
Use this as the header:
$header = "MIME-Version: 1.0\r\n";
$header .= "Content-type: text/html; charset: utf8\r\n";
that's if you want to use HTML in the body, but you have to create well formatted HTML, you know with all of its tags: html, head, body, and close them all.
<html>
<head></head>
<body>Content here and this is a link</body>
</html>
I had the same problem once, turned out my spam filter blocked the mail when a link was in it and let it trough when I removed the link.
Took me some time to notice that
The one email From:support#lead.com works fine. But when changed to john.doe#lead.com it doesn't work? See below.
Both are valid email addresses (fictitious for this example) in the domain from which they are sent.
I have the question into Netfirms support too. I expect to move to phpmailer or API to a ESP (e.g., mailchimp) account soon, but this is just bugging me that the little change breaks the email function.
Code:
Works:
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: support#lead.com' . "\r\n";
$headers .= 'Bcc: bcc#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#mylead.com")) echo ("Message delivery failed");
Doesn't Work: (only changed support to john.doe):
$headers = "Mime-Version: 1.0\n";
$headers .= "Content-Type: text/html;charset=UTF-8\n";
$headers .= 'From: john.doe#lead.com' . "\r\n";
// $headers .= 'Return-Path: bcc#lead.com' . "\r\n";
mb_internal_encoding("UTF-8");
if (!mail($to, $subject, $body, $headers, "-f bcc#lead.com")) echo ("Message delivery failed");
Don't know how this really should matter, but you're mixing \n and \r\n in the headers, which may confuse your mail server... Would you mind to try this out?
I am trying to figure out why the bcc part of this PHP mail function is not working in the code below:
function _send_user_email($to, $subject, $message) {
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Customer Service <support#mydomain.com>";
$headers[] = "Bcc: <support#mydomain.com>";
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, implode("\r\n", $headers));
}
I wouldn't think that there should be any problem specifying a bcc email address that is the same as the From address, but I'm not sure.
When I test this function, the recipient receives the message, but the BCC copy does not come through. Any idea why? Thanks.
Seriously, don't use the mail() function -- you're just letting yourself into a world of hurt.
If you want to do anything beyond absolutely the most basic email, I strongly recommend using a decent mail class, such as phpMailer.
It will make things much easier. No more messing around building the headers yourself, or trying to get the mime types working. Sending to multiple addresses, CC and BCC addresses becomes simple, and adding attachments goes from virtually impossible with mail() to dead simple.
Hope that helps.
try this one in your script you have to change "" to '' and also remove <> then it will be work here i edited your script
function _send_user_email($to, $subject, $message) {
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/html; charset=iso-8859-1";
$headers[] = "From: Customer Service <support#mydomain.com>";
$headers[] = 'Bcc: support#mydomain.com';
$headers[] = "X-Mailer: PHP/".phpversion();
mail($to, $subject, $message, implode("\r\n", $headers));
}
here my mail function example
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "From: mydemo.com<$your_email>\r\n" .
$headers .= 'Bcc: mydemo#mydemo.com' . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
mail($to, $subject, $message, $headers);
Now If You Want To Use Html In Message
$headers .= 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "X-Mailer: PHP/" . phpversion();
For Exampe Message
$message .='<table><tr><td></td></tr></table>';
Try to use Cci like this example:
$headers = array(
'From' => $from,
'To' => $to,
'Cci' => $bcc,
'Subject' => $subject
);
it working fine, i have tested the script found that email drop in Junk box.
try to add name of email holder :
"Bcc: Support <support#mydomain.com>";
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);