-
app/Http/Controllers/UserController.php
Open in GitHubuse Mail; use App\Mail\ContactUser; class UserController extends Controller { public function contact(User $user, Request $request) { $from_user = Auth::user(); $to_user = $user; if ($to_user->verified == 1) { if ($request->has('body')) { $body = $request->input('body'); Mail::to($to_user)->send(new ContactUser($from_user, $to_user, $body, $request->has('reveal_email'))); flash(trans('messages.message_sent')); return redirect()->route('users.contactform', $to_user); } else { flash(__('Please type a message')); return redirect()->back(); } } else { flash(__('The user you are trying to contact did not verify his/her email')); return redirect()->back(); } } }
-
app/Mail/ContactUser.php
Open in GitHubuse App\User; use Illuminate\Mail\Mailable; class ContactUser extends Mailable { public $body; public $to_user; public $from_user; public function __construct(User $from_user, User $to_user, $body, $reveal_email = false) { $this->body = $body; $this->from_user = $from_user; $this->to_user = $to_user; $this->reveal_email = $reveal_email; // wether to send as the sender user email or use the generic noreply from if ($reveal_email) { $this->replyTo($from_user); } } public function build() { return $this->markdown('emails.contact') ->from(config('mail.noreply'), config('mail.from.name')) ->subject('['.setting('name').'] '.trans('messages.a_message_for_you')); } }