firefly-iii/app/Handlers/Events/SendRegistrationMail.php

68 lines
1.5 KiB
PHP
Raw Normal View History

<?php
/**
* SendRegistrationMail.php
2016-04-01 09:44:46 -05:00
* Copyright (C) 2016 thegrumpydictator@gmail.com
*
* This software may be modified and distributed under the terms
* of the MIT license. See the LICENSE file for details.
*/
declare(strict_types = 1);
namespace FireflyIII\Handlers\Events;
use FireflyIII\Events\UserRegistration;
use Illuminate\Mail\Message;
use Log;
use Mail;
use Swift_TransportException;
/**
* Class SendRegistrationMail
*
* @package FireflyIII\Handlers\Events
*/
class SendRegistrationMail
{
/**
* Create the event listener.
*
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param UserRegistration $event
*
2016-04-06 09:37:28 -05:00
* @return bool
*/
2016-04-06 09:37:28 -05:00
public function handle(UserRegistration $event): bool
{
$sendMail = env('SEND_REGISTRATION_MAIL', true);
if (!$sendMail) {
2016-04-06 09:37:28 -05:00
return true;
}
// get the email address
$email = $event->user->email;
$address = route('index');
2016-03-29 09:10:51 -05:00
$ipAddress = $event->ipAddress;
// send email.
try {
Mail::send(
['emails.registered-html', 'emails.registered'], ['address' => $address, 'ip' => $ipAddress], function (Message $message) use ($email) {
$message->to($email, $email)->subject('Welcome to Firefly III! ');
}
);
} catch (Swift_TransportException $e) {
Log::error($e->getMessage());
}
2016-04-25 11:43:09 -05:00
2016-04-06 09:37:28 -05:00
return true;
}
2016-03-29 09:17:06 -05:00
}