I've tried all the possible solutions available here in stackoverflow, however nothing... I think the problem is related to the firewall, I can send mail using SMTP gmail on my local machine, but not in my server, I get the following message:
Connection could not be established with host smtp.gmail.com [Connection timed out #110]
I've tried the following commands:
ufw allow 587/tcp
iptables -I OUTPUT -p tcp --dport 587 -j DROP
iptables -I OUTPUT -d smtp.gmail.com -p tcp -m tcp --dport 587 -j ACCEPT
iptables -L OUTPUT -n
However not worked...
This is my .env email settings:
MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=*****@gmail.com
MAIL_PASSWORD=*****
MAIL_ENCRYPTION=tls
My controller for sending emails:
public function postEmail(PostEmailRequest $request)
{
if ($request){
Mail::send('app.pages.contato.email', $request->all(), function($message) use ($request)
{
$message->from($request->email , config('settings.website_title'));
$message->to(config('settings.admin_email'))->subject($request->assunto);
});
return redirect('contato');
}else{
return redirect('contato')->withErrors($request);
}
}