发送邮件和验证实际的电子邮件?

I am sending users an activation link via php, I only have a regex in place to check if the email consists of *@*.* which is fine, but I would like to check if the email actually sends also.

I tried to do this with

if (mail(....)) {
     // success
} else {
     // error
}

But when I enter an email of a@a.a it still goes through to the success step.

How can I actually check if it is a correct email in php, thanks.

From the PHP docs

bool mail( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

Returns TRUE if the mail was successfully accepted for delivery, FALSE otherwise.

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.

Just because an email address is formatted properly does not mean that there is an actual mailbox at that location. There is no way in PHP to "check" if a email address exists/is active. That is the entire purpose of activation links, to verify that someone is checking that email address.

  1. validate the email address preoperly with

     if (filter_var($email_a, FILTER_VALIDATE_EMAIL)) {
         echo "VALID";
     }
    
  2. the email server will return true on accepting the email it does not know if it will get to the user the only way to do this , and i'm sure you have seen it, is to get the recipient to click on a link in the email that sends them back to your site, then you know its valid\used address.

+1 for filter_var(). Use it instead of a simple regexp. Even the most complex regexp can't get every possible way of putting together an RFC 5322 compliant address. Your attempt to come up with something is pretty much guaranteed to fail.

But you didn't ask about address format verification, you asked about checking to see that the mail was sent. The whole purpose of an activation link is to validate the email address. If you clean up unvalidated accounts on a regular basis, it doesn't matter whether the email address is structured correctly. By sending a link, you're doing a full-circuit test that bypasses any possible format misinterpretations that filter_var() might have.