PHP sendmail doesn`t send #RU domain Emails [duplicate] - php

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
Closed 3 years ago.
I'm using Laravel 5.8 for web development.
I made a short contact form , From where visitors are able to send me email with some data: name, their email, text ect...
I'm facing problem with #ru domain emails. They are not delivered into my inbox
Here is my .ENV
MAIL_DRIVER=sendmail
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=achelashvili22#gmail.com
MAIL_PASSWORD=myemailpassword
MAIL_ENCRYPTION=tls
My code in controller:
$from = 'test#testmail.com';
$to = "achelashvili22#gmail.com";
$subject = "Checking PHP mail";
$message = "PHP mail works just fine";
$headers = "From:" . $from;
mail($to,$subject,$message, $headers);
My form sends emails normally. Problem appears when I input #ru domain emails. when I change test#testmail.com with any Russian Domain email, for example avtandil1994#mail.ru
I'm getting mail Error in eebmail:
achelashvili22#gmail.com
host gmail-smtp-in.l.google.com [64.233.184.26]
SMTP error from remote mail server after end of data:
550-5.7.1 **Unauthenticated** email from mail.ru is not accepted due to domain's
550-5.7.1 **DMARC policy**. Please contact the administrator of mail.ru domain if
550-5.7.1 this was a legitimate mail. Please visit
550-5.7.1 https://support.google.com/mail/answer/2451690 to learn about the
550 5.7.1 DMARC initiative. x1si17683973wrm.306 - gsmtp
I have also done this for my email
Allow Access for Unreliable apps
and also using Mailable, but problem remains to be the same.

It's an issue behind the scenes. It is the kind, how your system delivers mail to the world.
If you have not setup a mail gateway, your system tries to send the mail directly to the mail gate of the receiver; it is identified by the MX record of DNS. And here nearly all mail servers have it own politics, which from and try mails are accepted.
The better way is to use a gateway to your provider and let it distribute the mails. The provider usually wants an authentication of the client. Therefore see the docu of your 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.

mail(): SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 7 years ago.
Improve this question
Just recently and by accident, I found out that I cannot send emails to foreign sources beyond my server (I've been testing it with local Email addresses being installed at the same server). This is my code and I cannot send to (e.g.) gmail or yahoo.
$receiver = $emailadr;
$subj = 'Auth';
$msg = 'Thank you!';
$header = 'From: sometestmail#somedomain.com' . "\r\n" .
'Reply-To: sometestmail#somedomain.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion() . "\r\n" . 'Content-type: text/html; charset=iso-8859-1';
mail($receiver, $subj, $msg, $header);
When (attempting) sending, it comes up with this:
: mail(): SMTP server response: 503 This mail server requires authentication when attempting to send to a non-local e-mail address. Please check your mail client settings or contact your administrator to verify that the domain or address is defined for this server.
I'm using Plesk 12.5
Error message is quite clear This mail server requires authentication
You can create mail user in Plesk and use following PHP class to send mail with authentication:
http://phpmailer.worxware.com/index.php?pg=tutorial#2
Also you can try some cloud mail services like http://sendgrid.com/ they have nice PHP API library.
Looks like a problem of the mailserver. Your codes is on a shared hosting? Your provider probably has an anti-spam configuration (hopefully). You have to make sure that your sender address is existing. For testing, it's also helpful if you send the message to yourself (if you didn't already), this has more chances to work and then you can check the mail headers.
On a average configured e-mail server, there are four ways of mail communication: (i assume your server is running somedomain.com and is providing #somedomain.com mails)
Incoming: Mails from not-#somedomain.com to #somedomain.com. These mails are normally simply accepted.
Outgoing: Mails from #somedomain.com to not-#somedomain.com. There mails are accepted if the origin IP address is in the local network (or the webserver). That's what you want
Internal: Mails from #somedomain.com to #somedomain.com. That's another option for you, if you send the message to yourself. Here you have the highest change that the mail arrives
Relay: Mails from not-#somedomain.com to not-#somedomain.com. This is what your server thinks you are doing. Relaying mails is normally denied except for authenticated users because it's normally spam (and that's what it tells you in the error message). Unfortunately, the standard PHP sendmail function doesn't support authentication. Because of this, you need to add the sender address to the mailserver's whitelist or (easier:) change it to an accepted internal address which changes your mail to an outgoing or internal one, depending on the receiver address.

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.

Sendding emails is not working on SMF

My forum has a problem with sending emails :
i have configured my mail settings as the following :
Mail Type : smtp
SMTP Host : myhost
Port : 587
Username & password : a valid email account on my domain
when i click on forget password to test sending emails i got the following message in error log:
Sender address is not valid for your login. Check your email program settings
I am pretty sure that this account is correct, and i tried to add test mail script to my host with the following code :
<?php
$mail = mail("myEmail", "wahahahahahaahahahahaa","I like spamming your inbox!!!", "From: Myself<your_email#here.com");
if(!$mail){
echo 'mail is not sent!';
} else {
echo 'mail is sent :-)';
}
?>
and it prints
mail is sent :-)
What i am missing here ?
I agree with Eggyal - it sounds like the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
To confirm this, and to rule-out a problem with the way that your application is trying to send the message - you might want to try sending a message through this SMTP server using a standard mail client (such as Thunderbird or Outlook), and using the same MAIL FROM address and authentication credentials that your application is using. If this fails with the same error, then you've confirmed that the hosted SMTP server is not allowing mail to be sent from the MAIL FROM address that you are using, with the authentication credentials that you are using.
Problem Solved.
I added my gmail on webmaster email, i changed it to domain email user then the problem is solved

Categories