php mail function - php

I am using PHP to send an email with headers like this:
From: danny#mydomain.com
To: dannyfriend#gmail.com
When I check the headers in dannyfriend#gmail.com's (the recipient) email client, I see this header:
Received: from admin by gator1815.hostgator.com with local (Exim 4.69)
(envelope-from <danny#mydomain.com>)
But sometimes the mail goes to dannyfriend's spam folder, because the email is sent via hostgator.com not via mydomain.com as in the sender's email address.
What is really happening here? Why isn't it like this:
Received: from admin by somename.mydomain.com with local (Exim 4.69)
(envelope-from <danny#mydomain.com>)
I have seen an article describing this problem. Can somebody shine some light on what is happening with the SMTP server?
Summary:
Why is the SMTP server not using the message from FROM: header as the envelope-from?

You are actually using anonymous smtp relay. Your ISP provider probably the hostgator in that case is sending email on behalf of the email address that you are using. You may need to qualify your server to be a valid SMTP server that can receive and send emails. If the header does not match the actual from domain, the mail client or the receiving end suspects that it is coming from a fraudulent address and marks it as spam.

Related

Problem at sending email with SwiftMailer library in Laravel 5.5.44

I have this problem in Laravel 5.5.44 with Swift Mailer package trying to sending emails. This is the mail that the Swift Mailer package send to the server responsible for sending e-mails to the users:
This is the mail system at host user-ws.localdomain.
I'm sorry to have to inform you that your message could not
be delivered to one or more recipients. It's attached below.
For further assistance, please send mail to postmaster.
If you do so, please include this problem report. You can
delete your own text from the attached returned message.
The mail system
<cxxx#gmail.com>: host gmail-smtp-in.l.google.com[74.125.71.26] said:
550-5.7.1 [41.X.X.X] The IP address sending this message does not have a
PTR 550-5.7.1 record setup. As a policy, Gmail does not accept messages
from IPs 550-5.7.1 with missing PTR records. Please visit 550-5.7.1
https://support.google.com/mail/answer/81126#authentication for more 550
5.7.1 information. p10-v6si4248809wrw.296 - gsmtp (in reply to end of DATA
command)
Can you guys help me?
Well, the error message that you received from googlemail is quite clear:
As a policy, Gmail does not accept messages from IPs 550-5.7.1 with
missing PTR records.
This means that the domain that you use in the FROM: header of your mail must have a DNS A-record pointed to the IP address of the host from which the email was sent.
To clarify:
your domain: example.com
your FROM adress: whitejson#example.com
your IP: 1.2.3.4
A-Record of domain example.com must map to IP 1.2.3.4 in your DNS server.
If the server is only in your local network it will be impossible to send a mail to googlemail that does not comply with this rule.
If you want to earn +2 reputation then mark this answer as accepted.

postfix mail not sent to gmail due to not authorized

I have setup a postfix mail server to my local ubuntu system. it sends mail properly but for gmail account it is not received from gmail account.
here is the output of maillog
Jun 15 14:29:33 aum30 postfix/smtp[29509]: D2E95360910: to=, relay=gmail-smtp-in.l.google.com[74.125.24.26]:25, delay=3, delays=0.09/0/2.3/0.69, dsn=5.7.1, status=bounced (host gmail-smtp-in.l.google.com[74.125.24.26] said: 550-5.7.1 [117.223.148.98] The IP you're using to send mail is not authorized to 550-5.7.1 send email directly to our servers. Please use the SMTP relay at your 550-5.7.1 service provider instead. Learn more at 550 5.7.1 https://support.google.com/mail/?p=NotAuthorizedError g2si1886184plk.487 - gsmtp (in reply to end of DATA command))
How can I solve this?
Your ISP may provide SMTP relays which will accept mail from your IP, and these servers should be authorized to send mail.
Your IP 117.223.148.98 is on the PBL: https://www.spamhaus.org/pbl/query/PBL1528741

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.

Codeigniter email being blocked by with yahoo domains

Hi I have a problem with my script sending emails out. Basically my script sends an email out like this:
From: zyz#yahoo.com
to: order#abc.ca
Even though the script is being sent out from #abc domain (Similiar to how gmail users send yahoo emails out from their account).
I get this message back from my server log:
550-5.7.1 Unauthenticated email from yahoo.com is not accepted due to domain's 550-5.7.1 DMARC policy.
Is there a way to bypass this with $config settings? Using a different smtp outgoing server?
Here is my email code:
$config['wordwrap'] = FALSE;
$config['mailtype'] = 'html';
$this->email->initialize($config);
$a=$this->load->view('cart/email',$data,true);
$this->email->from($data['email'], $data['fname'].' '.$data['lname']);
$this->email->to('order#abc.ca');
$this->email->subject('Your Order');
$this->email->message($a);
$this->email->send();
echo $this->email->print_debugger();
You should consider adding an SPF record with your domain name provider.
http://en.wikipedia.org/wiki/Sender_Policy_Framework
Your mail server neither conforms to Yahoo's DKIM nor is listed in the SPF record for yahoo.com, so the receiving mail server does not accept your message.
Your options to fix this include:
get Yahoo to add your IP to the SPF record (not likely)
have your server use your credentials to send the mail through Yahoo's outbound mail server https://answers.yahoo.com/question/index?qid=20120221123159AAYqXz1
use a from address in a domain that does not use SPF/DKIM
use a from address in the #abc domain and use the abc domain outbound mail server

BATV; What is it and how is it configured?

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.

Categories