Mails : casted

Casted mails

The casted mails are mails that have been properly configured and initiated to send. This does not check the environment but only checks if a user tried to send a mail. This means that a mail may be sent or not sent naturally due to offline mode. Howvever, they have been authorized to send. It is an higher level testing that does not require mails to be truly sent even when they were sent. All mails that were sent but failed to deliver (due to offline or some mail error) and those that were truly delivered fall into the category of casted mails. This means that for a mail to be casted, it must have been sent or attempted. The casted method is however used to test the environment in which a mail was attempted.

The example below provides an insight into how this is done.
Sample: Checking casted mails
  <?php

    $mailer = new Mailer;
    
    $mailer->server('mail.server'); // load server config file  
    
    $mailer->setup([

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

    ]);

    $mailer->sendmail('mail.template');
    
    if($mail->casted(!online)) {        
        
        //... mail was forwarded in while offline. 
        
    }
    
In the example above, the casted() method was used to check if attempt to send a mail was done while in offline environment. This may be helpful in code structuring and organization.