first set config/mail.php, as an example the gmail:
'driver' => 'smtp',
'host' => 'smtp.gmail.com',
'port' => 465,
'username' => '[email protected]', //email valid which will send the message
'password' => 'testpassword',
'sendmail' => '/usr/sbin/sendmail -bs',
contact.blade.php
{{ Form::open( array("action" => "MailController@send") ) }}
<div>
<label for="name"><b>Name</b></label>
<input required type="text" name="name" id="name">
</div>
<div>
<label for="message"><b>Message</b></label>
<textarea rows="6" name="message" id="message"></textarea>
</div>
<div>
{{ Form::submit('Send') }}
</div>
</form>
@if ( isset($success) )
<center>
<div class="alert alert-success">
<h4>Send Message</h4>
thanks
</div>
</center>
@endif
@if ( count($errors) > 0)
<div class="alert alert-error">
<h4>Required fields:</h4>
@foreach ($errors->all() as $e)
<li>{{ $e }}</li>
@endforeach
</div>
@endif
MailController.php
class MailController extends BaseController {
public function send() {
$rules = array('name' => 'required', 'message' => 'required');
$validation = Validator::make(Input::all(), $rules);
if ($validation->fails()) {
return Redirect::to('contact')->withErrors($validation->errors())->withInput();
} else {
//email.blade.php name of view
Mail::send('email', Input::all() , function($m){
$m
->from(Input::get('name'))
->to('[email protected]') //Email you want to send
->subject('Site:');
});
return View::make('contact')->with('success', TRUE);
}
email.blade.php
<h1>MESSAGE</h1>
<p>
<strong>Name: </strong>
{{$name}}
</p>
<p>
<strong>Message: </strong>
{{$message}}
</p>
Route
Route::post('contact', 'MailController@send');
There are some ways to e-mail, also for AJAX. I showed you one way, I hope this has Helped. ;)
What would my routes look like? Thanks for your response by the way!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community