Use mail port 587`` or either465```,
MAIL_PORT= 587 or 465
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hii
I have created a simple contact form to send mail on website owner email id , everything is working fine on my localserver im getting the mail , but when uploaded on hosting its giving me below error
Connection could not be established with host smtp.mailtrap.io [Connection refused #111]
When i googled this error i came to know instead of smtp mail driver use sendmail or mailgun , yeah when i did this i didn' get error and got the success msg , but not receiving the mail .
also i have tried config:clear cmd .
please tell me where am i going wrong.
My code
.env
MAIL_DRIVER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=25
MAIL_USERNAME=myusername
MAIL_PASSWORD=mypass
MAIL_ENCRYPTION=
mailcontroller
Mail::send(new SendMail);
return back()->with('msg','Thank You For Contacting us,we will get back to you soon');
sendmail.php
public function build(Request $request)
{
return $this->view('email',['fname'=>$request->fname,'lname'=>$request->lname,'msg'=>$request->msg,'mobile'=>$request->mobile,'email'=>$request->email])->to('[email protected]')->subject('Website Contact Form');
}
Thanks in advance
You need to identify if the issue is mailgun or your code. Follow the setup from below
And try sending a mailable through tinker. If it works it's your code, otherwise it's your server/network setup.
If it's your network( which I suspect from it works in localhost), from the command line of your server (not your pc) try telnet smtp.mailgun.org 25 replacing the detials with your setup. If this errors you have a network issue that we cant really help with ;(
Please or to participate in this conversation.