2016-03-28 19:50:24 +02:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* SendRegistrationMail.php
|
2016-04-01 16:44:46 +02:00
|
|
|
* Copyright (C) 2016 thegrumpydictator@gmail.com
|
2016-03-28 19:50:24 +02:00
|
|
|
*
|
2016-10-05 06:52:15 +02:00
|
|
|
* This software may be modified and distributed under the terms of the
|
|
|
|
* Creative Commons Attribution-ShareAlike 4.0 International License.
|
|
|
|
*
|
|
|
|
* See the LICENSE file for details.
|
2016-03-28 19:50:24 +02:00
|
|
|
*/
|
|
|
|
|
2016-05-20 12:27:31 +02:00
|
|
|
declare(strict_types = 1);
|
|
|
|
|
2016-03-28 19:50:24 +02:00
|
|
|
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 16:37:28 +02:00
|
|
|
* @return bool
|
2016-03-28 19:50:24 +02:00
|
|
|
*/
|
2016-04-06 16:37:28 +02:00
|
|
|
public function handle(UserRegistration $event): bool
|
2016-03-28 19:50:24 +02:00
|
|
|
{
|
|
|
|
$sendMail = env('SEND_REGISTRATION_MAIL', true);
|
|
|
|
if (!$sendMail) {
|
2016-04-06 16:37:28 +02:00
|
|
|
return true;
|
2016-03-28 19:50:24 +02:00
|
|
|
}
|
|
|
|
// get the email address
|
|
|
|
$email = $event->user->email;
|
|
|
|
$address = route('index');
|
2016-03-29 16:10:51 +02:00
|
|
|
$ipAddress = $event->ipAddress;
|
2016-03-28 19:50:24 +02:00
|
|
|
// 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 18:43:09 +02:00
|
|
|
|
2016-04-06 16:37:28 +02:00
|
|
|
return true;
|
2016-03-28 19:50:24 +02:00
|
|
|
}
|
2016-03-29 16:17:06 +02:00
|
|
|
}
|