The example below provides an insight into how this is done.
Sample: Checking sent mails
<?php
$mailer = new Mailer;
$mailer->authorize(true);
$mailer->server('mail.server');
$mailer->setup([
'client' => ['name' => 'Foo']
]);
$mailer->sendmail('mail.template');
if($mail->sent('online') || $mail->sent('offline')) {
//... mail was situationally forwarded.
}
In the example above, notice that the
online and offline
parameters were supplied as strings not constants. The sent('online')
was used to check if a mail was truly sent in online mode. For this to work, success
response has to be returned by the PHPMailer in an online environment after a message
has been sent. If the first test fails, then sent('offline') checks if the
environment was offline and mail was casted in that offline environment. If the second argument
tests postive, then the code block is executed. The second test will only return positive
for an offline environment where a mail is casted. By default, the sent() method is
set for an online environment. So $mail->sent() returns positive only when a message is truly
sent in online environment.