Php mail(), how to get undelivered address list? - php

I'm getting single emails, for each undelivered address that mail() send couldn't reach.
Since this can be a painfull process, to keep copy pasting every single address, I'm wondering if it's possible to access a LOG or something ?
Some notes:
- I've got this app running on a GoDaddy server (I know it sucks);
Thanks for your atention ;D

There is no log as such, because feedback from the receiving mail server is not immediate. There's only the "undeliverable" messages that get returned to you.
However, it should be possible to specify a reply-to or errors-to address pointing to a separate mailbox. That would make it easier to find out which recipient addresses failed.
That is the best way I can think of to group failed messages.

I'm wondering if it's possible to access a LOG or something ?
Maybe - it depends on what the MTA (mail transport agent) is, how it's configured and whether you have the permissions to access the file.
I've got this app running on a GoDaddy server
Then the above are all questions for your GoDaddy provider.
The MTA log should record details of messages which the MTA failed to offload elsewhere but the elsewhere may be a smart relay (i.e. still on the sending side) - in which case you'd need to look at the relay MTA's logs to see if it managed to pass the message on to one of the recipient MXs. Even if the message got as far as a recipient MX, you don't know that it was successfully delivered. By convention, the receiving system should send back a DSN if it fails (and you can specifically ask for a DSN regardless of outcome) but a lot of systems don't implement this properly.
Regardless it may provide information about some messages which fail - you'd need to poll the return mailbox to identify failures.
C.

If mail() fails immediately, it returns false and you went get any e-mail. However, if a problem arises after the mail has been sent but before it has been received, you get an e-mail.
The mail() function will send the e-mail to some mailserver, which will send it to another, until it reaches its destination. When the user does not exist, this is only discovered at the destination mail server and it responds with an e-mail, called a bounce.
There is no way to group these bounce e-mails, as the destination mail servers do not know that they came from the same script.

Another option you have is to pipe the incoming emails to a PHP script and process it that way. How this is accomplished depends on the server setup you have and whether your server is set up to use sendmail or exim.
A good tutorial on this is located here.

Related

mail () SMPT error (5050) sending failed 5.1.1) PHP

I am having a problem that I have never encountered in my life.
In practice we have a website where we receive reservations, the A record is pointed towards our vps for the management of the site instead the part of mail is managed by aruba since the customer has preferred to leave their mail client. (for a matter of convenience because they have been using it for some time)
Going to the problem ..
the php mail () function when trying to send an email to the email: info#dominio.it our server returns as an error:
SMPT error (5050) sending failed 5.1.1)
in practice it is as if the email does not exist and was looking for it on our server but in reality it is located on aruba.
How can I tell the php mail () function to search for this mail not locally but on aruba?
with regard
Fabrizio C.
This only lays partial in php itself. You php.ini configuration file allows you to set a few settings
See:
https://www.php.net/manual/en/mail.configuration.php
The rest of the configuration need to be done in the MTA(Mail Transfer Agent) as in outgoing emails server of your VPS. Hard to say what you are using there..
Also according to your text, it looks like you tink the a record had something to do with your email...
a correctly configurated MTA does the following on an email address.
username#domain.tld
It requests the MX requests of domain.tld, and does not use an A record.
Then tries the MX records in order of their priority to deliver the email.
(This also is outside the scope of PHP, but might be good to know)

Record/copies of PHP mail() previously sent from our website?

Should there be a record of all php sent mail (via our hosts mail() function) anywhere?
Our web developer made an oversight and all enquiries sent via the our host's (godaddy.com) mailer relay for the last 2 months were rejected by our local mail server. Naturally, our server doesn't keep any rejected emails.
I have spoken to godaddy.com and they claim there is no record, however I'm not particularly confident with the answer.
Is there anything I can do? The enquiry form is now fixed (used Mandrill), so that's not an issue.
No, the mails are gone now.
Rejected mails that a mail server tried to send usually go to the mail admin account of the sending server as a bounce - however, even that account might not be set up or failing or rejecting mail, so the mail server will get rid of these undeliverable mails that double-bounced by deleting them from the queue.
You might get an idea of what was tried to mail if you are able to get your hand onto a mail server logfile, but assuming this is in the hands of your hosting provider, your chances are low: 1. these logs would only give you an idea of which mail addresses were involved, but no content. 2. the log files usually get deleted quickly because they'd serve no regular purpose.

PHP mails going into spam from Amazon Ec2

I have an application hosted on amazon EC2. Now a user can send out invitations to join but on most email clients its showing up in the spam folder. Is there anyway to find out on what criteria it is actually being filtered.
First of all, please check to see if your domain/IP has landed on any blacklists:
https://www.mxtoolbox.com/blacklists.aspx
Second of all, have you set an SPF record? Explanation below:
http://www.openspf.org/Introduction
https://mxtoolbox.com/spf.aspx
This is a way to qualify a particular server/IP as being a valid for relaying/sending mail on behalf of a particular domain. Sendmail - or whatever PHP is configured to use to send mail - can actually send mail for any user on any domain (i.e. "spoofing"). However the server receiving the mail (e.g. a recipients POP3 server where received mail is stored and filtered) is probably going to check whether or not that server is supposed to be sending mail for that domain based on what's in the domain's DNS entries. In particular, it will probably check the SPF record, so you will need to set this. You should consult whichever service manages your DNS (i.e. your nameservers) for how to do this. You can look up where your nameservers are using the whois, dig or nslookup commands (or just use a web based whois service) - look for the "nameserver" entries, often denoted by "ns".
This is one of a number of factors that may be affecting whether or not your mail goes to spam. This subject is something of a "can of worms" and goes way beyond setting up your PHP mail function correctly. Rather than trying to reiterate all of these issues here, I'll direct you to this post on serverfault:
https://serverfault.com/questions/106598/all-my-emails-to-yahoo-hotmail-and-aol-are-going-to-spam-though-ive-implemen
Do you use 5th parameter in mail function?
mail('reciever#address.com', 'the subject', 'the message', null,
'-fyour#address.com');
It helps sometime.
Also maybe your IP was blocked before you start to use it.

A couple problems re: CodeIgniter emailer

I have some problems with the email system for CodeIgniter:
First, the emails I send out (registration, confirmations) are getting caught in standard spam filters in gmail and other mail clients. How do I get around this? How do companies like Facebook get their emails through consistently?
Second, the mailer is working locally but once we deploy it it no longer runs (doesn't send emails) but all the other forms run just fine. Anyone ever run into a problem like this?
Thanks for all the help!
I can't really answer your first question - it's not specific to CodeIgniter. You just need to make sure your email doesn't look like spam. In short - there's no way of guaranteeing your e-mail will not end up in a spam filter.
As for the second question, I expect your production server needs to be configured properly for email. You probably need to configure CodeIgniter to send email properly. I would suggest setting up an SMTP server (or using an existing one) rather than using the standard PHP mail which I think CodeIgniter uses by default.
Regarding spam, most organisations are very secretive about how they prevent spam (not wanting to publish information which helps the spammers) and in some cases they don't actually know - an obvious examlpe of this is bayesian filtering - but, for example, hotmail use a completely unaccountable army of volunteers to manually classify emails.
Do and get a copy of spamassassin and try to reverse engineer how the standard rules work. Obvious things to check are:
1) AVOIDING LOTS OF CAPITALS
2) don't mention the 'V' word
3) make sure you've got a current and restrictive SPF 1.0 policy published
4) make sure your sending from an address which has A and PTR DNS records
5) Do provide a reply-to and from email address which use your domain in the address
the mailer is working locally but once we deploy it it no longer runs
doesn't send emails
Which? These are 2 totally seperate things. If the code is falling over (if so why have you not provided the error details) then its likely a PHP version issue or a problem with the connection to the MTA (or the PHP mail config).
The latter is a problem with the MTA itself.
99.9% of problems reported as PHP mail failures have nothing to do with PHP and are problems with the MTA.
Enabled detailled error reporting for your MTA and see where it is failing.
C.
You may have to configure the email on your server differently than your local development environment. I've had to in the past.
There are two basic ways that PHP can send mail:
Via a UNIX program called "sendmail" (only on non-Windows servers and only if it is installed - check with your hosting provider)
Via a SMTP server.
If you've configured CodeIgniter to use SENDMAIL, check to ensure that the Sendmail path is correct. Your hosting provider usually provides this somewhere in their online documentation.
If you're using SMTP, you need to make sure that your server can contact the SMTP server. You can do this by logging into the server via SSH and typing "telnet your.smtpserver.com 25". If you get an error message about not being able to connect, you know you have a problem with your hosting provider connecting to your mail server.
I've been able to diagnose this problem by enabling logging on my production server (http://bit.ly/4pprd6) and adding log_message('error', $this->email->print_debugger()) right after I attempt to send a message.

Success verification of mail() function PHP

Is it possible to check if the php can get some kind of a ping/flag back from exchange mail server to say "yes, email has been sent off to the intended recipient"?
According to the PHP manual, the return of mail() boolean could mean; "It is important to note that just because the mail was accepted for delivery, it does NOT mean the mail will actually reach the intended destination."
Does this mean, PHP can return success but actually there could be a problem on the mail server that php wouldn't know about it? and in this case no email has been sent and the user is none the wiser?
TIA
Jared
The mail() function will just connect via SMTP to the server and send the message. Then if the server says the server has received the message, mail will return successfully.
In the meantime, things can go wrong. The user's account could be deleted, the harddisk on the mailserver could crash, the SMTP server could fail to find the user's mail server. The user's mail server could reject the message because the user's mailbox is full. Many, many things could go wrong.
This isn't PHP's fault. And no reasonable improvement could be made to any programming language API to make sure someone got the message. But some companies like CampaignMonitor offer a paid service that will check for bounces and if people open the message to update mailing your mailing lists. Using APIs from services like these, you could check in a few days if the message was successfully received.
So the PHP docs are just saying, 'We can only tell you if the first SMTP server said they got it. Any number of issues could happen between the computers from there to the person with the email account.'

Categories