Support the ongoing development of Laravel.io →
Database Mail Testing
Last updated 2 years ago.
0

here is my registration, email confirmation posting.

public function registerPost()
{
	$validator = Validator::make(Input::all(), User::$rules);

	if ($validator->passes()) {
		// validation has passed, save user in DB
		$user = new User;
		$confirmation_code = str_random(30);
		$user->firstname = Input::get('firstname');
		$user->lastname = Input::get('lastname');
		$user->username = Input::get('username');
		$user->email = Input::get('email');
		$user->password = Hash::make(Input::get('password'));
		$user->confirmation_code = $confirmation_code;
		$user->save();		
		
		// Add user to 'User' group
		$group = Group::where('name_short','=','user')->first();
		$group->user()->attach($user->id);

		//send confirmation email
		Mail::queue('emails.auth.verify', array('confirmation_code' => $confirmation_code, 'username' => $user->username), function($message) {
			$message->to(Input::get('email'), Input::get('firstname') . ' ' . Input::get('lastname'))
				->subject('mysite.co - Verify your email address')
				->from('[email protected]','MySite.co');
		});

		Session::flash('success_msg', 'Thanks for registering! You will need to verify your email ( '.$user->email.' ) before you can access the site.<br>Please allow up to 5 minutes. If you do not receive confirmation by then <b><a href="'.URL::to("users/verify-resend").'" class="alert-link">click here</a></b> for the option to resend.');
		return Redirect::route('home');
	} else {
		// validation has failed, display error messages
		return Redirect::route('register')->withErrors($validator)->withInput();
	}
}

You should use Mail::queue. That way the user isn't waiting. Also, if it is taking a while for your server to process sending the email it may be a PHP setting.

And then of course in app/config/Mail.php change the following settings

'driver' => 'mailgun',
'host' => 'smtp.mailgun.org',
'port' => 587,
'from' => array('address' => '[email protected]', 'name' => 'MySite.co'), // Set global From here. Can also be set in Mail::queue/Mail::send
'encryption' => 'tls',
'username' => '[email protected]', // Username from mailgun.org - look at image below
'password' => 'mysecretsmtppassword', // Password from mailgun.org - look at image below

Here is an image of the mailgun page alt text

Also, look in the mailgun logs page for your domain. sometimes it takes quite a while for them to send. But you will at least be able to see that they are in queue there.


also - app\config\services.php

'mailgun' => array(
	'domain' => 'mysite.co',
	'secret' => 'key-mysecretapikey',
),
Last updated 9 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.