/** * Send message through contact * * @param ContactRequest $request * @param UserMailer $mailer * @return \Illuminate\Http\RedirectResponse */ public function doContact(ContactRequest $request, UserMailer $mailer) { if (!canContact()) { return redirect()->route('home'); } $mailer->contact($request->all()); return redirect()->back()->with('status', 'Yep'); }
/** * Handle the event. * * @param UserWasCreated $event * @return void */ public function handle(UserWasCreated $event) { if (!canContact()) { $this->auth->login($event->user); return; } $user = $this->userService->generateConfirmation($event->user); $this->mailer->confirm($user); }
/** * Allow a user to send an email. * * - Send an email to the user - allow the sender to write the message. * - Can either be passed a user ID as uid or a message id as msg. * - Does not check permissions for a message ID as there is no information disclosed. * - accessed by ?action=emailuser;sa=email */ public function action_email() { global $context, $user_info, $txt, $scripturl; // Can the user even see this information? if ($user_info['is_guest']) { fatal_lang_error('no_access', false); } isAllowedTo('send_email_to_members'); // Are we sending to a user? $context['form_hidden_vars'] = array(); if (isset($_REQUEST['uid'])) { require_once SUBSDIR . '/Members.subs.php'; // Get the latest activated member's display name. $row = getBasicMemberData((int) $_REQUEST['uid']); $context['form_hidden_vars']['uid'] = (int) $_REQUEST['uid']; } elseif (isset($_REQUEST['msg'])) { require_once SUBSDIR . '/Messages.subs.php'; $row = mailFromMessage((int) $_REQUEST['msg']); $context['form_hidden_vars']['msg'] = (int) $_REQUEST['msg']; } // Are you sure you got the address or any data? if (empty($row['email_address']) || empty($row)) { fatal_lang_error('cant_find_user_email'); } // Can they actually do this? $context['show_email_address'] = showEmailAddress(!empty($row['hide_email']), $row['id_member']); if ($context['show_email_address'] === 'no') { fatal_lang_error('no_access', false); } // Does the user want to be contacted at all by you? require_once SUBSDIR . '/Members.subs.php'; if (!canContact($row['id_member'])) { fatal_lang_error('no_access', false); } // Setup the context! $context['recipient'] = array('id' => $row['id_member'], 'name' => $row['real_name'], 'email' => $row['email_address'], 'email_link' => ($context['show_email_address'] == 'yes_permission_override' ? '<em>' : '') . '<a href="mailto:' . $row['email_address'] . '">' . $row['email_address'] . '</a>' . ($context['show_email_address'] == 'yes_permission_override' ? '</em>' : ''), 'link' => $row['id_member'] ? '<a href="' . $scripturl . '?action=profile;u=' . $row['id_member'] . '">' . $row['real_name'] . '</a>' : $row['real_name']); // Can we see this person's email address? $context['can_view_recipient_email'] = $context['show_email_address'] == 'yes' || $context['show_email_address'] == 'yes_permission_override'; // Template $context['sub_template'] = 'custom_email'; $context['page_title'] = $txt['send_email']; // Are we actually sending it? if (isset($_POST['send']) && isset($_POST['email_body'])) { checkSession(); // Don't let them send too many! spamProtection('sendmail'); require_once SUBSDIR . '/Mail.subs.php'; require_once SUBSDIR . '/DataValidator.class.php'; // We will need to do some data checking $validator = new Data_Validator(); $validator->sanitation_rules(array('y_name' => 'trim', 'email_body' => 'trim', 'email_subject' => 'trim')); $validator->validation_rules(array('y_name' => 'required|notequal[_]', 'y_email' => 'required|valid_email', 'email_body' => 'required', 'email_subject' => 'required')); $validator->text_replacements(array('y_name' => $txt['sendtopic_sender_name'], 'y_email' => $txt['sendtopic_sender_email'], 'email_body' => $txt['message'], 'email_subject' => $txt['send_email_subject'])); $validator->validate($_POST); // If it's a guest sort out their names. if ($user_info['is_guest']) { $errors = $validator->validation_errors(array('y_name', 'y_email')); if ($errors) { $context['sendemail_error'] = array('errors' => $errors, 'type' => 'minor', 'title' => $txt['validation_failure']); return; } $from_name = $validator->y_name; $from_email = $validator->y_email; } else { $from_name = $user_info['name']; $from_email = $user_info['email']; } // Check we have a body (etc). $errors = $validator->validation_errors(array('email_body', 'email_subject')); if (!empty($errors)) { $context['sendemail_error'] = array('errors' => $errors, 'type' => 'minor', 'title' => $txt['validation_failure']); return; } // We use a template in case they want to customise! $replacements = array('EMAILSUBJECT' => $validator->email_subject, 'EMAILBODY' => $validator->email_body, 'SENDERNAME' => $from_name, 'RECPNAME' => $context['recipient']['name']); // Get the template and get out! $emaildata = loadEmailTemplate('send_email', $replacements); sendmail($context['recipient']['email'], $emaildata['subject'], $emaildata['body'], $from_email, null, false, 1, null, true); // Now work out where to go! if (isset($_REQUEST['uid'])) { redirectexit('action=profile;u=' . (int) $_REQUEST['uid']); } elseif (isset($_REQUEST['msg'])) { redirectexit('msg=' . (int) $_REQUEST['msg']); } else { redirectexit(); } } }