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

**URL:** <https://discourse.laminas.dev/t/zf2-email-sending-properly-how-do-i-know-if-email-has-not-sent/2186>\
**Category:** Components & MVC\
**Tags:** zend-mvc, zend-mail\
**Created:** [March 16, 2021, 12:13pm UTC](https://discourse.laminas.dev/t/zf2-email-sending-properly-how-do-i-know-if-email-has-not-sent/2186 "2021-03-16T12:13:50Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Aawshirazeem](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/aawshirazeem/32/884_2.png) [@Aawshirazeem](https://discourse.laminas.dev/u/Aawshirazeem)\
**Post date:** [March 16, 2021, 12:13pm UTC](https://discourse.laminas.dev/t/zf2-email-sending-properly-how-do-i-know-if-email-has-not-sent/2186/1 "2021-03-16T12:13:50Z")

</div>

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](mailto: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;
```

---

<div class="post-metadata">

**Author:** ![froschdesign](https://yyz2.discourse-cdn.com/flex032/user_avatar/discourse.laminas.dev/froschdesign/32/38_2.png) [@froschdesign](https://discourse.laminas.dev/u/froschdesign)\
**Post date:** [March 16, 2021, 2:37pm UTC](https://discourse.laminas.dev/t/zf2-email-sending-properly-how-do-i-know-if-email-has-not-sent/2186/2 "2021-03-16T14:37:57Z")

</div>

> [@Aawshirazeem](#):
>
> I would like to know how can i determine email has not sent successfully…

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](https://www.php.net/manual/en/function.mail.php#refsect1-function.mail-returnvalues):

> 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. 😉  
Check Stackoverflow or something else for more background.
