I am facing a weird problem. When I send out mails using PHP's mail() function, the mail is being sent perfectly to gmail and yahoo(though it was marked as spam in yahoo), but the mail is not received by my company's email address.
I don't have direct access to the server, only ftp to the public_html folder, hence I can't check the logs.....
Any ideas or suggestions?
EDIT:
$mailfrom="website#mysite.com";
$mailto=$buyerrow['email'];
$subject="Test Details";
$body='Hi '.$buyerrow['name'].'!<br>Test Details below:<br><br><br><br><br>Thanks<br>Web Team';
$headers = "MIME-Version: 1.0\r\n";
$headers.= "Content-type: text/html; carset=iso-8859-1;\r\n";
$headers.= "From: ADMIN <".$mailfrom.">\r\n";
#mail($mailto,$subject,$body,$headers,"-f website#mysite.com");
As for the spam folders at my company's server, I am quite sure it didn't end up there either....
Is it possible that there is some server setting which allows php to send mail to only particular server?
Many company mailservers are set up to outright reject some types of spam immediately during the SMTP session. If that happens, it will never make it to your companies spam folder. You should check with your company system administrator.
If you're in doubt, you can always use an application like Wireshark to capture and analyse the actual SMTP traffic.
Have you checked on the Spam folder ? also check whether you have set HEADERS properly with from name etc.,
The problem seems to be with your company's server mail server.
Make sure to test it [send email from yahoo to your company email address] and double check the mx records.
Related
Building a site that currently doesn't have "https".
Trying to test out a login scheme that sends a validation email.
Tried out PHP's mail() function, and it worked, except that the email went into Spam in the receiver's Gmail. (This is my first time playing with mail()).
The Question: Will using SSL on the site (enabling "https") solve this problem? If not, then what will? (Realize that using something like PHPMailer is better, but mail() is much much simpler to implement so would prefer using it instead -- if at all possible.)
Error:
Script:
<?php
$to="receiver's email address";
$subject="sub: test mail from mail1.php";
$body="body: test mail from mail1.php";
$from = "sender's email address";
$headers = "From:".$from;
mail($to,$subject,$body,$headers);
?>
Will using SSL on my site (enabling "https") solve this problem?
No. Whether or not the recipient server considers your email to be spam has nothing to do with whether or not the website on the server that sent the mail is using HTTPS. The encryption complaint has to do with your local email server, not your web server.
If not, then what will?
Note that the fact your email is in the spam folder is not necessarily because of the lack of encryption. Implementing encryption on your local email server may help but could be a pain -- you'd have to refer to the docs for whatever email server you're running.
You can likely improve your chances by implementing SPF and DKIM on your side.
PHPMailer will not necessarily fare any better. I would recommend a mail service like MailGun instead. They will take care of the SSL for you, and provide services like bounce detection.
Try sending header before the mail() function, for example:
$header = "From: noreply#example.com\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header.= "Content-Type: text/html; charset=ISO-8859-1\r\n";
$header.= "X-Priority: 1\r\n";
.
.
.
mail($to,$subject,$body,$headers);
In case this doesn't fix your problem. Please try using PHPMailer instead.
Download the library from https://github.com/PHPMailer/PHPMailer
I stumbled on the following script today for sending an e-mail using PHPMail.
<?php
$to = "some_address#domain.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "my_address#domain.com";
$headers = "From:" . $from;
mail($to, $subject, $message, $headers);
echo "Mail Sent.";
?>
Above can be runnable through php mail.php and instantly you'll get an e-mail sent to $to from $from despite not needing to set outgoing/ingoing servers out.
It really intrigued me, since my CMS uses an SMTP outgoing server (well, same way Mail PHP does), which I need to set up with my Outlook SMTP username and password - some sort of verification.
However, about Mail PHP just.. sends an e-mail. To the address you set it as. From the address you set it as.
Looking at PHP docs it does not really reveal how it works. Does Mail PHP not have any issues with spamming since anyone can send anyone anything anytime programmatically without verification of the from identity?
EDIT:
It's rather funny the people in the comments were talking about the POTUS, since I had the exact thing in mind:
It did land in my junk folder, but I'm sure it isn't hard to make this look convincing enough and still be considered "oh damn spam filter lost my e-mail!"
The mail function uses the settings from php.ini. The details of this configuration can be found in Mail Runtime Configuration.
The defaults can be set in php.ini, although you can override them using ini_set.
I bet you sent the mail from a PHP script on a hosted server. That server probably has SMTP settings configured beforehand. If you would try this locally on a WAMP/LAMP server, you would have to do this configuration yourself, since PHP cannot read your Outlook/WhateverMailclient settings.
As stated in the comments, you can specify the sender/from address yourself. SMTP doesn't require this to be the actual sender domain, so that's why this works. The missing link is the pre-configured SMTP server of your host.
Some relay servers do check for this, and your mail might be blocked or sent to a junk mail folder. You can however configure this in your DNS to indicate that <Your server's IP> is indeed allowed to send email for <yourdomain>. For more information about that subject, you might want to read this question on ServerFault.
It uses the smtp protocol or send_mail, you can even configure what php should use to send mails in php.ini. It can send e-mail but the e-mail will end-up in your spam filter take a look to DKIM and SPF records for more information
My mail function is not working. My mail function is as follows:
function sendmail($from,$to,$sub,$msg)
{
$subject=$sub;
$message=$msg;
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= "From: <'.$from.'>" . "\r\n";
mail($to,$subject,$message,$headers);
}
This works fine in some of my other project but not working in a new project of mine.
It may be mail not working in your server.
Check with a basic mail function and upload it in your root to test mail.
testmail.php
<?php
$msg = "This is test mail";
mail("tester#email.com","My subject",$msg);
?>
If mail not working then try with authenticated mail like phpmailer, sendmail.
PHP inbuilt mail() function wont work in ur localhost or the server WHICH DOES NOT support smtp server. If you are running this project in ur pc locally then this mail function wont work. you need to upload it in server and then try, it will work!
If you are running this project in server and your mail doesn't fire then possibilities are :
1) You are hosted it in Windows server which supports PHP but not smtp.
2) If server is Linux, then server might have disabled outgoing mail. pls contact your server
I suggest you to use PHPMailer [https://github.com/Synchro/PHPMailer] which sends mail through external SMTP server like GMail,Hotmail etc.. give it a try..
I finally solved the issue. The problem was I had given my gmail id as admin id ( i.e, from address) now i changed it to a mail id from the domain name(say, if the domain name is www.abc.com I gave id as noreply#abc.com) and it works.
And now i came to know that giving gmail or other mail ids will work in some cases in some servers but it wont work on all servers. So using mail id in domain name (noreply#abc.com) will solve this issue. Even though gmail ids works in some servers still it will give a error message in the body of mail or it will be a spam mail so it is better to use mail id derived from domain name like noreply#abc.com.
Thank You....
I have tested my email server on allaboutspam.com to see why the emails are beeing considered spam by hotmail and gmail servers.
The results was amongst other faults, the BATV.
This is the complete result from allaboutspam.com on my BATV:
BATV is a mechanism wherein an outgoing Email server adds a tag to the Envelope From address of all outgoing Emails. For example, if an Email address goes out with From address as <info#allaboutspam.com>, the Envelope From is changed to <prvs=SBDGAUJ=info#allaboutspam.com>, where 'SBDGAUJ' is the added tag. This tag is generated using an internal mechanism and is different for each email sent.
If any bounce is received by the Incoming email servers, they are checked to see if the Bounce address has the proper tag (in above case 'SBDGAUJ'). If not, the email is rejected.
Could somebody explain this in simpler words... How is it configured?
currently I have this setup when sending email with php:
$mail_message="text_text_text_text";
$headers="MIME-Version: 1.0"."\n";
$headers.="Content-type: text/plain; charset=UTF-8"."\n";
$headers.="From: Skuffen <no-reply#domain.se>"."\n";
$subject="SUBJECT HERE";
mail($email, '=?UTF-8?B?'.base64_encode($subject).'?=', $mail_message, $headers, '-fno-reply#domain.se');
This is a swedish language so you know (utf-8)...
Thanks
I think that you need to set this up in your Mail Transfer Agent. The PHP mail() command sends mail through the local sendmail (or compatible, like Exim, Postfix or Qmail) installation. That's where BATV needs to be configured.
If you are on a simple shared hosting, contact your hosting provider.
<?php
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
mail("example#gmail.com", "hello", "nothing",$headers);
echo "mail sent";
?>
but it does not actually send the mail please help me out with this
The mail function is just an interface to the local mail server. The mail functionality in PHP relies on the machine PHP is running on to be correctly configured and able to dispatch e-mail. Check the mail system configuration on the machine.
check the following -
check if your smtp server is running (you could either check through command line tools or try ftp'ing to port 25).
If your smtp server is running. Then try to send a mail manually (without script). Use the command-line mail command (I am assuming you have unix here).
Also, when you run your script, what happens? It could be possible that your mail is in a Queue. From your terminal type 'mailq'. This shows the current emails in Queue & why they are there. Also there is a corresponding log to this. You could also check that out for info.
My guess is if all the above are running, you are good to go.
please check following ** Please verify your servers sender domain policy**
Emails sent through your servers (mail servers and shared web servers) should use a from address that is hosted here at your server. Emails that are sent with a from address hosted somewhere else (like Hotmail or Google) may be blocked.
ie use
$header = "From:example#/*yourhostname.domain name*/ \r\n";