BATV; What is it and how is it configured? - php

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.

Related

Externally hosted email and using PHP to send email

I will be using G Suite (formally Google Apps) to host the email of a site that runs off a separate host.
However, there is a contact form on the website, I haven't looked at it yet, but I assume it will use the standard mail() function.
As I understand it mail() will still use the servers mail server to send the mail, it may be a dumb question, but I assume this won't cause any spam detection issues because of this? Like, I know some servers won't accept mail if the From and/or Sender headers don't match the server it is coming from (or in some cases if the email you set in these headers doesn't exist).
So, if the mail is hosted on G Suite, and the email address that is setup in the From/Sender headers exists on G Suite this won't cause any issues correct?
Lastly, I know it's probably a better idea to use SMTP to send the mail via Google, but I may not have that choice, so I wanted to find out the answer to the above just in-case.
Edit: As per Nima's answer, is this something that can be avoided, or only with using Googles SMTP server to send with?
If you want it simple, then simple use SMTP.
Because of spam, multiple mail server provider are blocking mails from mail servers that have no correct RDNS (Reverse DNS) and MTA name configured.
You want to make sure that all three names are matching according to your MX Record:
Sender Hostname (e.g *mail#demohost.com, note that from can be what ever you want)
MTA-Name/HELO-Hostname (Configured in Mailserver, e.g demohost.com)
RDNS (Basicly it gives per IP-Adress the Hostname (e.g 42.42.42.42 -> demohost.com)
Also make sure your php.ini has the correct configuration for your Mail Server. Congrats you can now send Mails using mail(...).
As I said, it's probably most simple by just using SMTP. Assign the hard work to a hoster.
When you use GSUITE for hosting emails, it's obvious that you will be providing some domain name to GSUITE.
Now emails are marked spam and not spam based on the content as well as certificates of sending server and sending servers have different services for Transactional and Marketing Oriented emails. And GSUITE only provide transactional mail service, and transactional mails from a mail service --having valid certificates and not black listed-- lands directly into Inbox or Other Label, but Spam/Promotion.
Now GSUITE is having all correct certificates and I don't think there is any consumer oriented mail service provider, which blocks emails coming from google servers.
Other Question:-
Does the From Address in E-MAIL headers matters?
Upto now I have never seen from address impacting anything on receiving servers, but some consumer mail services block the usage of from address other than the account email address, just like mobile operators don't let us use someone else's caller id(Ideally).
But mail service providers to businesses let you use any address as from value in e-mail headers.
Edit:-
If you are still unsure about delivery of emails, you can use replyTo header with out any problem.
PS:- I have tested this myself with thousands of emails but using SendGrid servers.
http://php.net/manual/en/function.mail.php
The Windows implementation of mail() differs in many ways from the
Unix implementation. First, it doesn't use a local binary for
composing messages but only operates on direct sockets which means a
MTA is needed listening on a network socket (which can either on the
localhost or a remote machine).
On linux the sendmail executable is used to talk to the SMTP server configured on windows you can / could configure mail() function to use SMTP
So the best way is to use SMTP directly to send the email to Gmail to send the email.
Taken from:
https://stackoverflow.com/a/33506709/623150
Here is a way to do it with PHP PEAR
// Pear Mail Library
require_once "Mail.php";
$from = '<your#mail.com>'; //change this to your email address
$to = '<someone#mail.com>'; // change to address
$subject = 'Insert subject here'; // subject of mail
$body = "Hello world! this is the content of the email"; //content of mail
$headers = array(
'From' => $from,
'To' => $to,
'Subject' => $subject
);
$smtp = Mail::factory('smtp', array(
'host' => 'ssl://smtp.gmail.com',
'port' => '465',
'auth' => true,
'username' => 'your#gmail.com', //your gmail account
'password' => 'snip' // your password
));
// Send the mail
$mail = $smtp->send($to, $headers, $body);
If you use gmail smtp remember to enable SMTP in you gmail account,
under settings
On a Linux Server you can't use SMTP via the mail function.

How does Mail PHP work?

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

PHP mail sender authentication warning

I am sending mail from my hosting server through this PHP code :
mail("myemail#gmail.com", "Subject: Verify Eg Net Solution ID", $randStr , "From: Egnetsolution#gmail.com" );
In myemail#gmail.com the email is send but there is a warning that is saying :
"This message may not have been sent by: Egnetsolution#gmail.com Learn more Report phishing"
What I have to do in my hosting domain server. I will really appreciate you if you can give me a solution.
Check this answer:
You can either set up google apps for your site and get a
Username#yourwebsite.com gmail account (more info here it's free), or
You will need to set up an e-mail address on your current server that
is Username#yourwebsite.com and use that as the $mail->from address.
Your E-Mail recipients are receiving the message because you are
telling google to send an e-mail from your server, and then you are
telling them that the mail is coming from gmail, which it isn't, it's
coming from your personal server. Since the from address and your
server address don't match, they flag it as spam. This is googles way
of preventing spam, to them it would be the same if you put
$mail->from(YOURMOM#LOL.com). The e-mail would still send, but your
domain name does not match the # address.

PHP: how to test mailing to localhost on Linux and actually receiving it?

I'm building a daemon in php that checks for received emails which it then stores in the database leading them through a whole process. The thing is that I want to build some unit tests for this, for which I don't want to setup a whole mail server.
So for tests I want to somehow send emails to localhost, which should then be picked up by the daemon and processed further. So I tried the following:
$headers = 'From: me#mydomain.com \r\n Reply-To: me#mydomain.com \r\n X-Mailer: PHP/' . phpversion();
mail('www-data#localhost', 'THE SUBJECT', 'THE BODY IS HERE', $headers);
When I then run mail from the command line, I just get a message saying No mail for kramer65.
So my question; does anybody know how I can send emails to localhost in php, and how I can then read these emails from within php again? All tips are welcome!
[EDIT]
So I figured that it is sending an email to the www-data account, and not to my personal kramer65 account. I changed the to email address into kramer65#localhost, and when I now run mail I get
kramer65#php0:~$ mail
Mail version 8.1.2 01/15/2001. Type ? for help.
"/var/mail/kramer65": 1 message 1 new
>N 1 kramer65e#php0 Fri Apr 25 10:48 16/495 THE SUBJECT
&
My following question is now; how do I read or somehow get this email from within php?
This depends on how you have configured the php internal mail settings. If you configured it to use a local mail forward agent (sendmail or similar) then you should be able to send messages to a local account (not a local email address) by just specifying the account name. At least this is what such agents offer. Unless php explicitly prevents such usage it might be worth a try.
You cannot send to a local email address, since that requires an email server, specifically an smtp server (exim or the like). Without it there is no component that could accept an incoming message.

Mail being sent to gmail, yahoo, but not to personal mail servers

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.

Categories