How to send email in laravel using your cpanel email smtp ?

Laravel provides easy way to send emails to your users, with laravel Mail providers. 


Step 1 - Setup your cpanel email smtp setting example following.

MAIL_DRIVER=smtp
MAIL_HOST=mail.example.com
MAIL_PORT=587
MAIL_USERNAME=info@example.com
MAIL_PASSWORD={LA{Q[Srtx@t
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS=info@example.com
MAIL_FROM_NAME="${APP_NAME}"


Step 2 -   Add  this to your controller's function and   define  use Mail; at the top


    $user = Users::findOrFail($id);
	$remember_token=rand();

	$html="Dear ".$user->name.",<br>
            Welcome to the Example Limited!!<br>
            Please click here or below link to verify your account.<br>
           <a href=\"http:example.com/".$remember_token."
            \"> Click here </a> <br> <br>
            Thanks,<br>Limited";


            Mail::send(array(), array(), function ($m) use ($user,$html) {
                $m->from('info@example.com', 'Laravel');
                $m->to($user->email, $user->name)->subject('Verify your Email!');
                $m->setBody($html, 'text/html');
            });

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...