XF 2.0 Send email to guest

AndyB

Well-known member
I would like to send an email to a guest.

The following code works great to send an email to a member:

PHP:
foreach ($members as $member)
{              
    $mail = \XF::app()->mailer()->newMail();

    $user = \XF::app()->find('XF:User', $member['user_id']);
    $mail->setToUser($user);

    $mail->setTemplate('andy_emailsubscription', [
        'threads' => $threads
    ]);

    $mail->queue();
}


However I'm trying to send to a guest so all I have is their email address. What code can I use to send an email to a guest?

Thank you.
 
Last edited:
Got it.

PHP:
foreach ($guests as $guest)
{
	$mail = \XF::app()->mailer()->newMail();
	$mail->setTo($guest['email']);

	$mail->setTemplate('andy_emailsubscription', [
		'threads' => $threads
	]);

	$mail->queue();
}
 
Back
Top Bottom