php - PHPMailer DSN How to get error when address not exist


I use PHPMailer for PHP5/6 and i try to make script witch will send mail and get error like "550 No Such User Here".

I read about DSN, and try tips from this How to set DSN (Delivery Status Notification) for PHPMailer? topic, but it's doesnt work. (i found functin recipient where was

return $this->sendCommand(
        'RCPT TO',
        'RCPT TO:<' . $toaddr . '>',
        array(250, 251)

and i try change link

'RCPT TO:<' . $toaddr . '>',


'RCPT TO:<' . $toaddr . '> NOTIFY=SUCCESS,FAILURE ORCPT=rfc822;' . $toaddr ."" .self::CRLF,

but i doesnt work. I was try add it by function AddCustomHeader but it fail too.

This is my code:

private function send($username, $password, $from, $nameFrom, $replay, $subject, $email) {
    try {
        $_ = Zend_Registry::get('Zend_Translate');
        $mail = new PHPMailer(true);

        $mail->SMTPDebug = 2;
        $mail->SMTPAuth = true;
        $mail->SMTPSecure = "tls";
        $mail->Host = "";
        $mail->Port = 587;
        $mail->SMTPKeepAlive = true;
        $mail->Username = $username;
        $mail->Password = $password;
        $mail->SetFrom($from, $nameFrom);
        $mail->AddReplyTo($replay, $nameFrom);
        $mail->Subject = $subject;
//            $mail->AddCustomHeader( "X-Confirm-Reading-To: [email protected]" );
//            $mail->AddCustomHeader( "NOTIFY=SUCCESS,FAILURE ORCPT=rfc822; $email" );
//            $mail->AddCustomHeader( "Disposition-Notification-To: [email protected]" );
//            $mail->AddCustomHeader( "Return-receipt-to: [email protected]" );
        if (!$mail->Send()) {
            return array(
                'status' => false,
                'message' => $mail->ErrorInfo
        } else {
            return array(
                'status' => true,
                'message' => $_->_('__MAIL_WAS_SEND__')
    } catch (Exception $e) {
        return array(
                'status' => false,
                'message' => $e->getMessage()
    catch (phpmailerException $e) {
        return array(
                'status' => false,
                'message' => $e->getMessage()

In result i have need script where: When i write real address, ex [email protected] it will be send, but when i write fake address, ex [email protected] will return me code 550, or any other error.

Is there any options to do this ? becouse i need to get and save all information.




Remember, that due to spambots and e-mail verifying scripts (such as yours). Many mail servers do not send those responses.

If they did, they would be flooded by spambots that would be asking for whole their mail databases (millions of records) if those e-mails exist.

For that reason, it's disabled on most mailservers nowdays.


Is there a way to test if an E-Mail address exists without sending a test mail?

How to check if an email address exists without sending an email?


Basically, every of those functions can be disabled by server admin. They may even return faked info etc. It's all to make it unsusable to spammers (legit uses got to suffer from this).

There are other methods to verify if e-mail exists. Ask for reply, for delivery confirmation etc.

Some servers when message could not be delivered return you e-mail. But that's not 100% sure behaviour, since spammers could spam servers with random generated e-mails and wait for returns.

Those measures are implemented to pervent spammers with brute-force mass e-mail checks.

They could run dictionary attack against google servers and quickly create list of all existing emails.

Don't know what you want achive, if you want to check if one of your newsletter subscribers deleted e-mail or grabbed e-mail from random site and want to confirm it.

You should follow one principle: All e-mails are unverified by default. You never know if its real or not unless it's been verified by recipent by clicking link, answering etc.
By me, there should be no status as "100% does not exist" since you're unable to verify it.

People are also looking for solutions to the problem: amazon web services - AWS SDK for PHP's S3 stream wrapper works for writing, but not for reading


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.