Mails : attempted

Checking attempted mails

The attempted mails are mails that have been tried. This could be in offline or online environment. They don't necessarily mean mails that have been truly forwarded. They can also mean mails that developer have tried to send. For a mail to be attempted, it means that the mail has been authorized to send after server and header configuration parameters have been set successfully. If the important configuration parameters like server configuration and the recipient have been set, when a mail is tried, then an attempt is made. The attempt method is used to check if a mail has been attempted. A mail must also be authorized to send before an attempt can be successfully made.

The example below shows how to check if a mail is attempted.
Sample: Fetching mail header data
  <?php
  
    $mail = new Mailer;
    
    $mail->server('mail.server'); // load server config file  
    
    $mail->setup([

        'client' => ['name' => 'Foo']

    ]);

    $mail->authorize(true);

    $mail->sendmail();

    if($mail->attempted()){
        
        // ...do this

    } else {

        // ...no attempt was made     

    }
            

If the authorize is not set as true or necessary config parameters needed to send a mail (server and recipient) are not set, the attempted() method returns false even if sendmail is used.