ZF2- Email Sending properly ( how do i know if email has not sent )

Hello Everyone,

I have used Zend f-2 to send emails to through cronjob. emails are sending sing and multiple perfectly.
That is working perfectly. what I would like to know is when There is wrong email address given ( for example : abc@abc.com ) I could not get any exception or error and returned it true. and on my email I received address not found

after sending email I am updating records that email has been sent. I would like to know how can i determine email has not sent successfully ( in the incorrect email case ) thanks You
my send function looks like this in Service

    $mail = new Mail\Message();
    $mail->setEncoding('UTF-8');

    $html = new MimePart($content);
    $html->type = 'text/html';
    $html->charset = 'UTF-8';
    $bodyParts = [$html];

    $body = new MimeMessage();
    $body->setParts($bodyParts);


    $mail->setBody($body);

    if (!$from) {
        $from = $this->config['email_addresses']['info'];
    }
    $mail->setFrom($from);

    $mail->addTo($to);

    $mail->setEncoding('UTF8');
    $mail->setSubject($subject);


    if ($this->config['useSmtp'] === true) {
        // Die extra Config Felder müssen entfernt werden,
        // da die Klasse SmtpOptions sonst nach einem Setter fragt den es nicht gibt.
        unset($this->config['email_addresses']);
        unset($this->config['useSmtp']);

        $transport = new Smtp();
        $transport->setOptions(new SmtpOptions($this->config));
    } else {
        $transport = new Sendmail();
    }

    $sent = true;
    // Email senden
    try {
        $transport->send($mail);
    } catch (\Exception $exception) {
        $sent = false;
       throw $exception;
    }

    return $sent;

There is no special method to check if the email has been sent. But this as nothing to do with laminas-mail, zend-mail or PHP’s mail method.

See at PHP’s mail documentation:

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.

The question is almost as old as PHP itself. :wink:
Check Stackoverflow or something else for more background.