Reputation: 599
I get the above error when I try to send an email from my Laravel 8 Project
Problem: The Mail_host points to mailtrap in my .env and not mailhog.
.env
MAIL_MAILER=smtp
MAIL_HOST=smtp.mailtrap.io
MAIL_PORT=2525
MAIL_USERNAME=**************
MAIL_PASSWORD=**************
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=admin@*******.sc.ke
MAIL_FROM_NAME="${APP_NAME}"
contact.blade.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Models\Contact;
use Mail;
class ContactController extends Controller
{
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
* @return \Illuminate\Http\Response
*/
public function store(Request $req)
{
$this->validate($req, [
'name' => 'required',
'email' => 'required|email',
'subject' => 'required',
'phone' => 'required',
'subject' => 'required',
'message' => 'required'
]);
$contact =new Contact;
$contact->name = $req -> name;
$contact->email = $req -> email;
$contact->phone = $req -> phone;
$contact->subject = $req -> subject;
$contact->message = $req -> message;
// Toastr::success('Your message has been well received , We will contact you soon');
$contact->save();
\Mail::send('client.contact_email',
array(
'name' => $req->get('name'),
'email' => $req->get('email'),
'subject' => $req->get('subject'),
'phone' => $req->get('phone'),
'message' => $req->get('message'),
), function($message) use ($req)
{
$message->from($req->email);
$message->to('[email protected]');
});
return back()->with('success', 'Hello, '.$contact->name. ' Your message has been well received.');
}
}
I have hosted the files on a shared Cpanel Hosting. Solution: I have already cleared the Cache, and also done php artisan optimize.
Upvotes: 2
Views: 5811
Reputation: 21
MAIL_DRIVER=smtp
MAIL_HOST=mail.YOUR_DOMAIN.sc.ke
MAIL_PORT=587
MAIL_USERNAME=user@YOUR_DOMAIN.sc.ke
MAIL_PASSWORD=YOUR_MAIL_PASSWORD
MAIL_ENCRYPTION=null
Upvotes: 1