I am using the following code to send email to members of my site. The script works and the email is recieved by the user. But, I do encounter encoding problems when emailing to Hotmail or Notes.
The code:
$to = "to#email.com";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/plain; charset="utf-8"; format="flowed"' . "\r\n";
$headers .= 'Content-Transfer-Encoding: 8bit'. "\n\r\n";
$headers .= "To: John Doe<john#doe.com>" . "\r\n" .
"From: John Smith<john#smith.com" . "\r\n" .
"Reply-To: john#doe.com" . "\r\n" .
"Return-Path: john#doe.com" . "\r\n" .
"Sender: john#doe.com" . "\r\n" .
"X-Sender: john#doe.com" . "\r\n" .
"X-Mailer: JohnDoe". "\r\n".
"X-Report-Abuse: Please report abuse to: john#doe.com";
//If the e-mail was successfully sent...
$subject = $translation[104];
if(mail($to, $subject, $message, $headers)){
}
Both the message and the subject contains the swedish letters Å, Ä and Ö. The actual message is correctly encoded and viewed in Hotmail, while the subject is not. You can view the image below for more information:
Image: http://www.aspkoll.se/imgo/649
I am confused. I've googled for days and tried different kind of solutions, but without any success I am afraid.
Can you please help me with this problem?
Appreciated!
Email subjects, and other header content, such as names, are encoded using RFC 2047
php.net comments on mail() give the following example:
mail($mail, "=?utf-8?B?".base64_encode ($subject)."?=", $message, $headers);
Try http://www.phpclasses.org/browse/file/919.html. It works for Yahoo mail, Gmail, Hotmail.
P.S.: Hotmail sucks. :)
Related
I read the other questions and solutions... which is why I'm frustrated. I didn't code this app, but I'm trying to retrofit it.
Currently it sends a confirmation email to the email address that gets entered by the customer in the field. When I comment out the mail($to,... part at the bottom, it breaks the confirmation email functionality, so I know I'm in the right place in the code.
I just want a duplicate email sent to my master email address. I thought if I just put another mail command under the functional one, but specified a static address instead of the $to var it would work... but it doesn't. I couldn't get the CC header functionality to work either based on other questions, so I thought just sending a duplicate email to another address would work just fine.
Here is the working code:
$sq2 = myQuery(" select * from admin ");
$dat2 = mysql_fetch_object($sq2);
$from = "reservations#duelingpianopiano.com";
$to = $email;
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= "From: $from" . "\r\n";
$headers .= "Reply-To: $from" . "\r\n";
/*$headers = "From: $from" . "\r\n" .
"Reply-To: $from" . "\r\n" .
'X-Mailer: PHP/' . phpversion();*/
mail("vmvijitha#gmail.com", $subject, "sendemailtemplate($templateid,$tid,$userid,$modification)".$mailcontent, $headers);
//return;
mail($to, $subject, $mailcontent, $headers);
I feel like if I should just be able to add this line at the bottom to send the exact same email confirmation redundantly to my master email address for safe keeping.
mail("reservations#duelingpianopiano.com", $subject, $mailcontent, $headers);
Note: I think this line is an artifact from the original developer, and I can't tell whether it's working or not.
mail("vmvijitha#gmail.com", $subject,...
What am I assuming wrong?
insert multiple addresses using comma-separator in single variable.
$email_to = "xxx#one.com, xxx#two.com, xxx#three.com"
mail($email_to, $subject, $mailcontent, $headers);
The mail() function in PHP works fine when sending to Gmail if I don't specify any headers. However, as soon as I try to add in headers, the function still returns true but I never get the email. The Gmail server seems to reject the delivery.
These are the headers I'm using:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: ' . $username . ' <' . $email . '>' . "\r\n";
$headers .= 'From: Blahblah <email#example.com>' . "\r\n";
mail($email, 'Subject', '<html><body>Body of message</body></html>', $headers);
I was hoping that someone could point out to me the flaw? I grabbed most of this code straight from the PHP manual, so one could understand my confusion and frustration. Thanks!
The bigger email services will not deliver mail sent from your own personal server in this manner.
Due to SPAM issues. All the big mail providers require SPF records, DKIM, and reverse DNS before they will accept your mail.
Some live/hotmail user's are not receiving html mail
Personally I prefer to be rid of that hassle and use a 3rd party mail server for all of my outgoing mails to my users.
$Headers .= "From: $Yourname <$YourEmail>\r\n";
or
$Headers .= 'From: '.$Yourname.'<'.$Youremail.'>'."\r\n";
or
$Headers .= 'From: '.$Yourname.' <".$Youremail.">' . "\r\n";
Give a try if any of this work?
I'm implementing a reporting mail in php. I'm using simple php mail function with header information as below:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: Daily Report <info#mydomain.com>' . "\r\n".
'Reply-To: info#mydomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$subject = "Report for Domain on ".date('Y-m-d');
$message = "Hello World Testing this mail function.";
$to = "alauddin.xxx#xxx.com";
if(!mail($to, $subject, $message, $headers))
{
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent at ".date("Y-m-d H:i");
}
Mail is working fine (I'm receiving this email) but the problem is that From Address is coming weird like:
On gmail:
Daily Report <info#mydomain.com> via mailgun.org
On outlook:
info=mydomain.com#mailgun.org on behalf of Daily Report <info#mydomain.com>
I think from address is coming with root user address
but I'm looking like:
Dail Report <info#mydomain.com>
Please guys help me. I've already spent almost 6 hours to resolve this over the internet... :(
Mailgun is an e-mail service. The reason why mailgun.org keeps showing up in your e-mail header is because your domain isn't verified.
Verify Domain Info/Instructions
<?php
// multiple recipients
$to = 'ali.dzinemedia#gmail.com';
// subject
$subject = 'Birthday Reminders for August';
// message
$message = '<html>
<head></head>
<body>Content here and this is a link</body>
</html>';
// To send HTML mail, the Content-type header must be set
// Additional headers
$headers = 'To: Mary <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <ali.dzinemedia#gmail.com>' . "\r\n";
$headers .= 'X-Mailer: PHP/' . phpversion();
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset: utf8\r\n";
echo "To : ".$to;
// Mail it
mail($to, $subject, $message, $headers);
?>
please solved this . when i added Download in the mail body mail not send.
if i remove this a tag mail sent and all other content display as per my requirement .
I dont know where is the exact problem, i m using godady hosting with PHP 5.3 version.
if any one have better solutions please share with me .
I've adjusted your code a little bit. Main change is in From: header - $header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$erm.= '<TR>
<TD WIDTH="50%">' . "Download-" . $j . '</TD>
<TD WIDTH="50%">Download</TD>
</TR>';
$from_id = "support#xyz.com";
$header = "From: \"HCS Support Team\" <$from_id>\r\n" . "Reply-To: $from_id\r\n";
$header .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$header .= 'MIME-Version: 1.0' . "\r\n";
$header .= 'X-Mailer: PHP/' . phpversion() . "\r\n";
$subject = "Request for Case Study Solution Received";
#mail("ali.dzinemedia#gmail.com", $subject, $erm, $header);
It seems the mail is being sent, but it goes straight to SPAM folder. Please read about spam rules which make the mails go to spam folder: http://spamassassin.apache.org/tests_3_3_x.html
In your case the main problem with gmail is probably it's being sent with standard PHP mail function. Please try PHPMailer or PEAR::Mail.
The rules which are met by spamassasin in your mail are:
HTML_MESSAGE
HTML_MIME_NO_HTML_TAG
MIME_HTML_ONLY
i am using this code :
$to = "someone#example.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "someonelse#example.com";
$headers = "From:" . $from;
mail($to,$subject,$message,$headers);
echo "Mail Sent.";
it sends email to my gmail's SPAM folder .
Suggest any solution .
i dont want to use any PEAR MAIL type way to send email or dont want to require and include any file.
This functions works without including/requiring any additional php file.
You should use proper header like this from PHP manual
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
// Additional headers
$headers .= 'To: Mary <mary#example.com>, Kelly <kelly#example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday#example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive#example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck#example.com' . "\r\n";
// Mail it
mail($to, $subject, $message, $headers);
The Gmail spam filter has lots of parts to it which determine the spamminess of mail. You could start by seeing the SPF record for your domain. Avoid using sales language, HTML and colours where possible in your email.
There's also an old but fun video from Google about how their spam filtering works.
It's all in the headers. I don't know how GMail works internally, but I've found on my projects that setting Reply-To can Content-Type headers seems to fix this.
See PHP mail() docs for an example of doing this.
(Note: I've got a PHP questionnaire/response system that sets these headers and the e-mails come through correctly to GMail, Hotmail and Yahoo! Mail).