I’m somewhat new to using Laravel 4 and Mailgun. I’ve looked over both documentations and managed to test a few emails successfully through a simple route as shown below:
Route::get('send_test_email', function() {
Mail::send('emails.registro', ['key' => 'value'], function($message) {
$message->subject('Welcome to the amazing experience');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to('[email protected]');
});
});
I accessed myapp/send_test_email in the browser and received an email.
However, I’m looking to send an email during user registration instead. I’ve set up a new route like this:
Route::get('mail', ['uses' => 'MailController@send', 'as' => 'send']);
Here’s the MailController I’m working with:
<?php
class MailController extends BaseController {
public function index() {
return View::make('signup');
}
public function send() {
Mail::send('emails.registro', $data, function($message) use
{
$message->subject('Welcome to the amazing experience');
$message->from(env('CONTACT_MAIL'), env('CONTACT_NAME'));
$message->to($user->email, $user->firstname);
});
}
}
I also added a form in the signup page like this:
{{ Form::open(['route' => 'send', 'method' => 'get']) }}
<div class="form-group">
{{ Form::label('username', 'Username', ['class' => 'sr-only']) }}
{{ Form::text('username', null, ['placeholder' => 'Username', 'required', 'minlength' => 6, 'class' => 'form-control']) }}
@foreach($errors->get('username', '<span class=error>:message</span>') as $message)
{{$message}}
@endforeach
</div>
<div class="form-group">
{{ Form::label('password', 'Password', ['class' => 'sr-only']) }}
{{ Form::password('password', ['placeholder' => 'Password', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
@foreach($errors->get('password', '<span class=error>:message</span>') as $message)
{{$message}}
@endforeach
</div>
<div class="form-group">
{{ Form::label('password_confirm', 'Confirm Password', ['class' => 'sr-only']) }}
{{ Form::password('password_confirmation', ['placeholder' => 'Confirm Password', 'required', 'minlength' => 8, 'class' => 'form-control']) }}
@foreach($errors->get('password_confirmation', '<span class=error>:message</span>') as $message)
{{$message}}
@endforeach
</div>
<div class="form-group">
{{ Form::label('email', 'Email', ['class' => 'sr-only']) }}
{{ Form::email('email', null, ['placeholder' => 'Email', 'required', 'class' => 'form-control']) }}
@foreach($errors->get('email', '<span class=error>:message</span>') as $message)
{{$message}}
@endforeach
</div>
<div class="form-group">
{{ Form::label('firstname', 'First Name', ['class' => 'sr-only']) }}
{{ Form::text('firstname', null, ['placeholder' => 'First Name', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::label('lastname', 'Last Name', ['class' => 'sr-only']) }}
{{ Form::text('lastname', null, ['placeholder' => 'Last Name', 'required', 'class' => 'form-control']) }}
</div>
<div class="form-group">
{{ Form::submit('Register', ['class' => 'btn btn-lg btn-block btn-kinbu']) }}
</div>
{{ Form::close() }}
But I’m encountering a Parse error: syntax error, unexpected 'Mail' (T_STRING) in the controller. Can anyone help me figure out what might be wrong?