I mail using php mail function to send e-mail. In my dev server its working fine but in live server e-mail goes to spam folder.
<?php
$to = "example#gmail.com";
$subject = "Registration";
$from = "example1#gmail.com";
$content = "Test";
$headers = "From: Test <" . strip_tags($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";
$res = mail($to,$subject,$content,$headers);
$headers = "From: Test <" . strip_tags($to) . ">\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";
$res2 = mail($from,$subject,$content,$headers);
The problem is simple that the PHP-Mail function is not using a well configured SMTP Server.
Nowadays Email-Clients and Servers perform massive checks on the emails sending server, like Reverse-DNS-Lookups, Graylisting and whatevs. All this tests will fail with the php mail() function. If you are using a dynamic ip, its even worse.
Use the PHPMailer-Class and configure it to use smtp-auth along with a well configured, dedicated SMTP Server (either a local one, or a remote one) and your problems are gone.
https://github.com/PHPMailer/PHPMailer
answered by mrdognose
and use full headers..
http://www.velvetblues.com/web-development-blog/avoid-spam-filters-with-php-mail-emails/
Prevent sent emails treated as junk mails using php mail function
Related
I am using PHP's mail() function to generate mails. Generated mail looks absolutely fine with correct email ids in 'To' and 'Cc' but mail gets delivered to 'To' only and not to 'Cc'.
Here is the code
$headers = "From: xyz#abc.com \r\n";
$headers .= "Reply-To: xyz#abc.com";
$headers .= "MIME-Version: 1.0" . "\r\n";
$headers .= "Cc: email1#abc.com ; email2#abc.com" . "\r\n";
$headers .= "X-Mailer: PHP/". phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1". "\r\n";
mail($to, $subject, $message, $headers);
Our organsation uses 365 for mails, and this issue has mostly cropped up since we started migration. I went through the php mail log and it seems to be fine to me.
How to fix this issue? Any suggestions?
PS. I feel that this issue has cropped up only since we moved to 365 some time ago. Also, does id 'xyz#abc.com' (sender) need to exist?
$headers .= "Reply-To: xyz#abc.com";
Where is the "\r\n" on this line?
For a proper and standardized PHP mailing library which will help your team to properly build emails, take a look at:
https://github.com/PHPMailer/PHPMailer
Replace the ; to an , in your CC line:
$headers .= "Cc: email1#abc.com ; email2#abc" . "\r\n";
Or send your mails over IMAP with a class like PHPMailer https://github.com/PHPMailer/PHPMailer
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?
<?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
Why does this send emails?
$from_admin = $_POST[EMAIL];
$message_admin = 'some html...';
mail($to_admin,"subject",$message_admin,"FROM:$from_admin");
This email looks like it came from my gmail account.
While this doesn't send the email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To:' . $to . "\r\n";
$headers .= 'From: Registration <register#myserver.org>' . "\r\n";
mail($to, $subject, $message, $headers);
When I contacted my hosting support, they said that I need to do SMTP authentication. But, then why does the first mail function work? I would be ok if its not actually using that server, but people can reply the the html email and still reach the correct account. Is there any way around this?
Using the php mail() function to send out emails when a user requests a login.
It was working fine last week, emails were being received by all my coworkers who share the same mail server for our company. Now however, the emails are not being received by that mail server, but received on others (comcast.net, uservoice.com, gmail.com, etc.) just fine.
No error from the php mail() function so the emails are being sent, just for whatever reason they are all of a sudden blocked by our mail server.
No settings have been changed to the php scripts or the mail server.
Any ideas??? I have tried everything!
<?PHP
$timestamp = date('Y-m-d H:i:s');
$to = 'james.hickman#MYCOMPANY.com';
$from = 'support#MYCOMPANY.uservoice.com';
$subject = 'Admin Test';
$message = 'Just a simple test message! - '.$timestamp;
$headers .= "Reply-To: ".$from."\r\n";
$headers .= "Return-Path: ".$from."\r\n";
$headers .= "From: ".$from."\r\n";
$headers .= "Organization: MYCOMPANY Support\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/plain; charset=iso-8859-1\r\n";
$headers .= "X-Priority: 3\r\n";
$headers .= "X-Mailer: PHP". phpversion() ."\r\n" ;
if(mail($to, $subject, $message, $headers, "-f ".$from))
echo "Success!";
else
echo "Failed";
?>
If you are able to send mail out to other services and just not your own server then the problem is not with php's mail function. Php's mail function just sends out mail and you yourself said that u are able to send mails to other hosts. So the problem is not as devious as it sounds. Try and check if your server is out of disk-space.