This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 7 years ago.
I have made a password recovery option in my website using php mail function. It works with gmail and yahoo but when the email is hotmail it does not works, I tried many time. When I tried with my companies email (outlook) nothing happens. It only works with gmail and yahoo. What can be wrong with it. the code I am using is her below:
$email= "customer_email_address";
$head = "From: \"Pizza Hut Pakistan\" <no-reply#pizzahut.com.pk>\n";
$head .= "X-Mailer: RegFormPHP\n";
$head .= "Priority: urgent\n";
$head .= "Importance: High\n";
$head .= "Content-Language: en-us\n";
$head .= "Reply-To: <no-reply#pizzahut.com.pk>\n";
$head .= "Organization: \"Pizza Hut Pakistan\"\n";
$head .= "Content-Type: text/html\r\n";
$msg = 'Click the link below to proceed <br><br>';
$msg .= 'http://'.$_SERVER['HTTP_HOST'].'/root_folder/forgotlink.php?id='.$unique_code_of_user;
mail($email, "website account password recovery", $msg, $head);
every thing is cool with gmail and yahoo. but..... nothing works with others....
Thanks
Hotmail is probably rejecting your emails thinking it's spam.
Hotmail is known to be a PITA when it comes to emails... You can check if you have correct DKIM and SPF parameters, see if your server isn't blacklisted, or better yet, use a mailing provider like MailChimp, SendGrid or similar to be sure your emails are sended in best conditions.
You can try class.phpmailer.php. It works for Yahoo, Hotmail, GMail,
I wrote a PHP script to send emails.
My script is like this:
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'From: abc#yahoo.com' . "\r\n";
// Email Variables
$toUser = "someone#yahoo.com"; // recipient
$subject = "testing"; // subject
$body = "<html><body><p>
Example of including an image via html \<img\> tag:
<br>
<img src='../images/profile.jpg'>
<br>
My new picture
<br></p></body></html>"; // content
if (mail($toUser,$subject,$body,$headers)) {
echo "sent";
} else {
echo "failed";
}
Well, of course I use a valid email address for sender and receiver. I did receive the email, but it goes to junk mail. So I went for google research. Is it because of my "header" script problem? If it isn't, then what could cause my script to send a junk mail? Any solution?
Please try this:
$headers ="From:<$from>\n";
$headers.="MIME-Version: 1.0\n";
$headers.="Content-type: text/html; charset=iso 8859-1";
mail($to,$subject,$body,$headers,"-f$from");
Perhaps the problem is that yahoo uses domainkeys verification, which will likely fail for your application given that the mail is not actually coming from yahoo's servers.
When I've once had a similar problem I looked at the headers and found out that my host uses SpamAssassin. So I googled for 'SpamAssassin score' and found a multitude of information on how to incorrectly (and thus correctly) form an email.
For example: SpamAssassin score list
1. Check mail content
As others have hinted it is probably marked as spam because your mail looks like spam.
I am not sure if you the script that you have posted is the actual one that you are testing.
If it has the actual mail body & headers, then running this message through a standard installation of SpamAssassin gives it a spam score of 4.9
X-Spam-Status: No, score=4.9 required=5.0 tests=BAYES_50,HTML_IMAGE_ONLY_04,
HTML_MESSAGE,MIME_HTML_ONLY,NO_DNS_FOR_FROM,NO_RELAYS autolearn=no
version=3.2.5
Since the email body has only HTML it has a greater chance of being handled with suspect by most anti-spam solutions.
2. Mail server's IP
Another aspect worth checking will be the IP address of your mail server. Any mail originating from dynamic IP addresses will potentially be considered as SPAM.
3. Blocklists
Also check if your IP address is listed in one of the block lists. To start with please check your IP address with http://www.spamhaus.org/lookup.lasso.
Use mxtoolbox.com to check the servers IP to be blacklisted or not. As well this website can help you with a couple of email related checks.
Of course there are a long list of checks running inside spam filters. As already suggested, check the email headers for details about the spam filters rating of the spam email.
Hope that helps!
**This Works Perfectly fine for me**
$to="reciever#reciever.com";
$subject="This is Your Message";
$from = 'Sender <noreply#sender.com>';
$body='Hi '.$name.', <br/><br>Now You can See Yor main in inbox';
$headers = "From: " .($from) . "\r\n";
$headers .= "Reply-To: ".($from) . "\r\n";
$headers .= "Return-Path: ".($from) . "\r\n";;
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n";
mail($to,$subject,$body,$headers);
I was having the same problem:
The problem is that when you specify content-type before the "From:" part , the mail comes as a spam.
But if you specify "From:" before the content part it comes as a normal mail and makes you smile and curious.
As schnalle said, one problem surely is that the smtp server that you use to send the email and the one thet you specify as From, is different.. the from's domain whould be the same that the server youre running on.
So, you can use the yahoo server to send the email (check if they allow the smtp remote connection, but i guess they do) connecting by smtp, and this will solve 1 problem.
Another one is the html contents without the alternative plain text contents, but, this one is less important.
I suggest you phpMailer, free and open-source php class to send email, easly to use (i use it event o send mail through gmail server)
On your server try to sort your SPF (Sender Policy Framework, Google for SPF record) record out.
Make sure you send your e-mails from an existing account on your server/domain.
Make sure you have the reply-to address in your header.
These are the basic things you can try.
if your website domain is mydomain.com then in From headers make sure to use someone#mydomain.com
Remove the Content-type: text/html and add $headers .= "X-Priority: 2\nX-MSmail-Priority: high"; to get rid of Spam. This method has been tried and tested.
the problem is, the server you're sending the mail from is not a yahoo server. most spam filters check if they match, otherwise it would (and is - or was) possible to easily fake the sender. ever wondered why you get spam from bill.gates AT microsoft.com or your own mail address?
You've got two solutions:
use Yahoo's SMTP using abc#yahoo.com credentials to send mail from abc#yahoo.com;
use other from, with your own domain;
You can try the mail class and test file that I have created here. I have tested the files and can send emails to my hotmail and gmail under a different mail name. The main reason why the emails are mark as junk is because the structure (both header and message) is not correctly done. In most cases, it is the line feed that is causing the problem.
I can use it to send mail with attachments to Gmail. However, the attachments dont work for hotmail. Hope this helps =)
You can check the files here..
I am creating a small company, and would like to send out emails to my clients once they have signed up for my service to activate their accounts. I am currently using PHP's mail() function, however I am worried that my emails are being filtered out by spam filters. Is there a better way to go about this?
$email = 'XZY Client Email address # somedomain.com';
$emailSubject = "Welcome to XYZ Service!";
$to = $email;
$subject .= "".$emailSubject."";
$headers .= "From: no-reply#XYZService.com\r\n" .
"X-Mailer: php";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$message = "<html><body>";
$message .= "Welcome to XYZ Service! \n Activate your account by clicking the following link: link...";
mail($to, $subject, $message, $headers);
Is there a way to authenticate these emails so that my clients know that they are from my actual service? Thank you in advance!
You can try to get your mail server white listed by some of the major postmasters (AOL, Gmail, Hotmail, etc.).
I am not sure if this is what you want, but you can setup a mail server to handle all your emails.
Try using that mail server for sending emails and see if they are still filtered or not.
BTW, setting up a mail server on *nix systems is free and worth giving a try.
I have a simple arcade site that people from my highschool use and for quite a while I've been using the method that you showed. I didn't look at my code to verify that they're identical, but they look fairly close and mine works with gmail and all other big name services I've ran into!
Just remember that some hosting companies limit the amount of PHP mail that can be sent per minute. Mine only allows 9 per minute, I know I've gotten suspended a few times on accident while running test mail sends, haha.
I have set automatically to send email to users from my website. but this email will place to spam of users with gmail accounts.However it is working fine with yahoo or hotmail accounts.
How should I solve this?
$to = "$Email";
$subject = "Greeting";
$message = 'message here';
$from = "sender#example.com";
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: sender#example.com" . "\r\n" .
"Reply-To: sender#example.com" . "\r\n";
mail($to,$subject,$message,$headers);
Since your headers appear to be correct, it's probably keying on something within the message. One of the things that SpamAssassin (no idea if this is what Gmail uses) keys on is a very short message like the above containing a hyperlink or graphic, so you may benefit by actually making your message a little longer. One of the ways to find out is to send it to your own gmail account and when it appears in your spam folder, examine the headers there for any added spam information. It may contain clues as to what spam engine Gmail is using or what rules your message is breaking.
Please have a look here:
Spam sent to Contacts -
Message Delivery
Hope this helps!
it should be of smtp configuration email and site information email id should be diffrent.
Send email using mail function working fine. but my question is how to auto save the mail in sent items folder when mail sent
i m using own smtp server and port no is 25
is any config needed on php ini file or i may use imap
my code is as follows
<?php
function send_email($from, $to, $subject, $message){
$headers = "From: ".$from."\r\n";
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "Content-type: text/html\r\n";
if (mail($to,$subject,$message,$headers) ) {
echo "email sent";
} else {
echo "email couldn't be sent";
}
}
$subject = "Helloooo!";
$message .= "<html><body>";
$message .= "<b>Hey! How are you today?</b>";
$message .= "<br>Regards";
$message .= "</body></html>";
send_email("frm addr", "MYEMAILADDRESS#gmail.com",
$subject ,
$message);
?>
"frm addr" is my own web address which is provided by my mail server
how to store or automatically save the mails to my sent item folder whenever i send a mail using the above function
with thanks in adv
R.Saravanakumar
You have to understand the mail() function works on a remote server. The function you send the E-Mail with does not know the concept of a "Sent mail" folder.
That said, it would probably be possible to have the mail server place a copy of the message in the "sent" folder of an IMAP mailbox running on the same server. That includes a lot of hassle, though, and requires root access to the server.
A much easier solution is having the mail() function send you a copy of every sent mail, and to set up an Outlook rule to copy those mails into your "sent" folder.
For that, you could for example add a specific string (like "mail sent from form 1234567", some random number that is unlikely to be repeated in a normal mail) to the subject when sending your copy. Your Outlook rule would then look out for mails containing that subject, and move them into the "Sent" folder (or any other folder, for that matter).
Storing a sent mail in a "sent item"-folder is done by the client which sends out emails, not the mailserver (which is used by mail()).
The PHP-mail()-function will "just" send out email, communicating with the server, without storing it anywhere, so to have your send messages stored anywhere you'll have to create your own "mail-client" which handles mails and folders. I doubt that's worth the effort, so why not just send your mails to a second mail-account and store them there?