I am developing a website with a contact-us page where guest users can send me an email using Gmail
. But anytime I try send the mail using the contact-us form, I get this error Swift_TransportException in StreamBuffer.php line 269: Connection could not be established with host smtp.gmail.com [ #0]
This is my mail.php
return [
'driver' => env('MAIL_DRIVER', 'smtp'),
'host' => env('MAIL_HOST', 'smtp.gmail.com'),
'port' => 587,
'from' => ['address' => '', 'name' => ''],
'encryption' => env('MAIL_ENCRYPTION', 'tls'),
'username' => env('MAIL_USERNAME'),
'password' => env(MAIL_PASSWORD),
'sendmail' => '/usr/sbin/sendmail -bs',
'pretend' => env('MAIL_PRETEND', false),
];
This is my mail.php
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=afecjaped@gmail.com
MAIL_PASSWORD=********
MAIL_ENCRYPTION=tls
This is the UserController.php
public function sendMail()
{
$input = Request::all();
$data = [
'name' => $input['name'],
'email' => $input['email'],
'subject' => $input['subject'],
'message' => $input['message']
];
$rules = User::$mailRules;
$validator = Validator::make($input, $rules);
if ($validator->fails()) {
return redirect()->back()->withErrors($validator)->withInput($input);
} else {
Mail::send('emails.send', $data, function($message) use ($data) {
$message->from(Input::get('email'))
->to('afecjaped@gmail.com')
->subject(Input::get('subject'));
});
return 'Email Successfully sent';
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire