Valid email address [duplicate] - php

This question already has answers here:
How to check if an email address exists without sending an email?
(15 answers)
Closed 7 years ago.
Up until Facebook closed it's doors on 'Public Post Search' I used to run a site that allowed for this function. Right now am building a new site and have a landing page that allows for the visitor (old or new) to sign up to be notified when the new site is up and running. This is done via email. Unfortunately I have suffered some people inputting non email addresses so solved that with a PHP function, however more recently I've started suffering from what are clearly not valid email addresses like 'foo#bar.com' etc...
Is there a recommended PHP function to check whether the email address is fully valid? If not, is there a free service which has an API that I could use to check whether the address is valid?

The only reliable way to know if an email address is valid is to attempt to send an email to that address and check for a hard or soft bounce.
You can validate that the format of the email address satisfies format checks and therefore could be valid. foo#bar.com would pass that check.
In the ancient days of the internet (the 90's), many SMTP servers would allow one to query "is this email address valid" without going through with sending an email. That was abused by spammers to validate spam lists, so pretty much every SMTP server has that part of the protocol disabled.

Related

Php mail() to GSuite/GMail Deliverability Issue, Not all GSuite Domains Impacted [duplicate]

This question already has answers here:
PHP mail function doesn't complete sending of e-mail
(31 answers)
can't send email to addresses at my own domain
(19 answers)
Closed 4 years ago.
I've run into a quirky GSuite/Gmail deliverability issue from a PHP mail() form on one of my websites. Here's the scenario in as much detail as I can give:
We have two businesses (A and B), each with its own domain. Both domains are set up in our corporate GSuite instance with BusinessA.com being primary.
I recently built a new website for BusinessB.com. The contact form on the site is programmed with PHP's mail() to email the form responses to 2 BusinessB.com addresses, however, the emails are not coming through. We've done the obligatory spam checks, and I've set up a new test account for BusinessB.com (testb#BusinessB.com). No BusinessB.com form response make it to the inbox. (Regular inbound and outbound email is working properly.)
To troubleshoot I added my BusinessA.com email along with an external (non-GSuite) Gmail address to the recipient list, both receive the form submissions with no issue.
Next, I added the alias testb#BusinessA.com to the testb#BusinessB.com test email address. When I add this alias to the recipient list, the form submission also comes through with no issue.
Last, I tested an existing BusinessA.com GSuite Group that forwards to the two original BusinessB.com addresses. The form responses sent to this group forward on to the two original recipients with no issue at all. (This is currently in place as a work-around, but I still need to resolve the issue)
Since the BusinessA.com address, the external Gmail address, the alias address, and the Gsuite Group all receive the email, I don't believe it is a result of a coding error.
It is important to note that prior to Business B's new domain and website they had a different domain, which resides also on the same hosting provider and is also set up as a domain in our corporate GSuite instance. There had been no form deliverability issues previously.
This leads me to believe it is something in GSuite on the domain level.
Are there domain specific settings that I am missing? Could it be a DNS record is needed? Am I thinking through this wrong?
UPDATE - solved the issue. After multiple additional attempts at rephrasing my search, I ran across this: can't send email to addresses at my own domain, while not the same question per se, #user2428118‘s answer did the trick. It was a setting in cpanel that made the difference. I already had the MX records that he mentioned so it was as easy as selecting the option of ‘remote mail exchanger’.

How to confirm sender of an incoming email? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
how to confirm email source
I would like to know how do email services such as Hotmail and Yahoo confirm that the "From" header was not spoofed. I mean, you didn't try to send an email in behalf of someone else.
I was now trying to spoof on Facebook Messages, using a php script to send an email to my #facebook.com email, spoofing the "From". I received it in behalf of that friend account. However, an alert saying "Unable to confirm --Friend Name-- as the sender." appeared.
What does Facebook (and other services) do to confirm that?
Please note that extensions (emailname+extension#mydomain.com) would not work for me. My idea is to simulate something similar as Facebook Messages support for emails.
I believe that just checking headers is not enough. I assume I'll have to check DNS/SPF stuff, but I'm not sure how to do that, and even what to do.
It would help me allot if you could indicate me some "algorithm" (preferentially in php) with steps to check for spoofing. Thank you!
As a domain owner you can implement SPF into your DNS zone. It allows you to set IP addresses of servers that are allowed to send mail on behalf of your domain. If another IP tries to send mail with your domain name as sender, it will be rejected by any mailserver that checks for SPF (and luckily, more and more start doing so!). There is never a hard guarantee that no one will ever send spoofed mail out of your name, but it significantly reduces the chance.
As Oldskool suggests, SPF is a widely used method for detecting falsified From (and reply-to) addresses - however most email providers use a much wider barrage of checking to seperate spam from ham.
Spamassassin is an open source project provide both a management program and a set of plugins (and an API for developing your own) including SPF for validating emails.

Detect expired e-mail addresses? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
How to check if an email address exists without sending an email?
Possible duplicate:
How to check if an email exists without sending an email?
I have a very big database with users (over 50000) and there are lots of automated e-mails the site sends out.
The problem is, quite a few of the addresses in the database (that users registered with years ago) have expired or have been deleted or no longer exist for whatever reason.
This creates an issue, because each user should have a valid e-mail.
I've been trying to find out if there's a way to detect whether an e-mail address is active, so we could update the database and prompt those users to enter a new e-mail? Something like a ping for e-mail addresses?
There's some code here that I've tried to figure out but to no avail:
http://www.webdigi.co.uk/blog/2009/how-to-check-if-an-email-address-exists-without-sending-an-email/smtpvalidateclassphp/
Does anyone have a solution?
Please note that I need a PHP solution, not command line since I have 50k e-mails to check.
Two things, first you should stop the influx of potentially in-valid email addresses by implementing a 'closed-loop' email verification system. Basically, when a user signs up for your site, you send an email with a link confirming their email address, and when they confirm, their account gets full access to your site.
Secondly, there is no real way to determine if an an email address is invalid strictly using PHP. I had to tackle this problem a few months ago, and we ended up using the mail-server to tell us if an email address has been bounced back or not. When your mail server sends an email, and the email cannot be delivered, the recipient mail-server will respond with a bounce notification to your mail-server which includes information as to why the email was bounced. Information such as a Delivery Status Notification (DSN) code which identifies why the email address couldn't be delivered.
Some example codes:
511: Bad Mailbox
512: Bad System
516: Mailbox Moved
These codes are made up of a prefix (4 or 5) to indicate a transient (temporary) or permanent failure. The following two digit code indicates an error range; two digit codes between 10 and 19 indicate an error relating to the email address, whereas codes between 20 and 29 indicate an error relating to the email mailbox.
From these codes you can determine, based on business requirements, a 'hard bounce' or a 'soft bounce'. A hard bounce would be something like 511 (bad mailbox), where it's certain that this email address is not currently valid. A soft bounce would be something like 445 (network congested), which indicates that it was a temporary issue as to why the email could not be delivered.
So in your instance, you could send out an email blast, and then track the bounces on your mail server. By looking at each bounce and the respective DSN code, you can flag whether an account's email is valid or not (we used PHP to gain access to the mail server and parse the bounce notifications for the DSN codes)
Here is more information on DSN codes.
-- Edit --
As Dagon wisely mentioned, you can pipe bounced emails into a PHP script upon their receipt. To do this you will need to read up on your mailserver config, but ours looks similar to the following:
bouncehandler unix - n n - - pipe
user=nobody argv=/usr/bin/php /path/to/BounceHandler.php
<% end %>
The only way to check if an e-mail address is expired or not is to send an e-mail message to it and see if you get a response. But note that doing so may be considered spamming, since it is an unsolicited message.
You can check if an e-mail address if properly formed, and if the mail server it specifies actually exists, but thats about it. There is no way that I know of to check if the account exists (and if a human is reading the mail sent there) without sending a mail with a link and requesting that the user click the link.

I want acknowledgment of mail [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicates:
Is there a way to determine whether an e-mail reaches its destination?
PHP: Check who had read sent email?
I need a php or zend framework code which return a acknowledgment when I send a mail.
If user receives a mail, or not, or may be email is not correct, or when user open this mail; in all these cases I to get a acknowledgement.
How do I do this?
The only way you can know if a user opened a mail to listen for resources (images) that will download to the client (if they allow downloads) otherwise you are in the dark.
Checking the mail was sent and if the address is valid can be done but only to a certain extend the server that sends the message will report if the message could be sent but that will only be the status of the sent message on that specific server. You could setup some kind of mechanism that listens for addresses that are reported by other servers as invalid but not all the servers do this ...
You could use a third-party provider to handle the acknoweldgements for you which will lift the burden from you. Like Mailchimp but they too have limited ways to do this.
Just my 2 cents
If you want to detect the mail being opened, you will need to embed an image in the e-mail. This image is generated by a PHP url like <img src="domain.com/index.php/generate_image/123"> where 123 is the User ID you put in the e-mail so you can track which user opened that e-mail.

Get Email Response of the user [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
how to make a php script that read an email from the server?
So I want an app to send the user an email, and the user has to respond. How do I capture what the user sent back to the email?
Check the In-Reply-To header of the reply to find out which message it relates to.
There are two possibilities:
Set up a regular off-the-shelf email server, and something to parse the inbox.
Set up a special php email server that listens on port 22 and processes the incoming mail - something like james but php-based. If nothing available you'll have to roll your own.
You have to create some cron job that will retrieve inbox of your email account.
I have implemented simmilar thing but I was using tokens system too - email that was send to user had a random generated token in topic. When user replied I was looking for that token and then associate it with some 'thread' (helpdesk system).

Categories