• This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn more.

XF 2.0 Send email to guest

AndyB

Well-known member
#1
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:

AndyB

Well-known member
#2
Got it.

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

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

	$mail->queue();
}