DWQA QuestionsCategory: Laravelhow to send mail using phpMailer in laravel?
kundan roy asked 5 years ago

Example :
step1 : install phpmail package
step2 : add following code above class where you want to write you mail code
use PHPMailerAutoload;
use PHPMailer;
 
step3: Write method as following
public function sendMailFrontEnd($email_content, $template)
{
$email_content[‘verification_token’] = Hash::make($email_content[‘receipent_email’]);
$email_content[’email’] = isset($email_content[‘receipent_email’])?$email_content[‘receipent_email’]:”;
$mail = new PHPMailer;
$html = view::make(’emails.’.$template,[‘content’ => $email_content]);
$html = $html->render();
try {
$mail->isSMTP(); // tell to use smtp
$mail->CharSet = “utf-8”; // set charset to utf8
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->Host = “mail.infowaynic.com”; // sets the SMTP server
$mail->Port = 587;
$mail->SMTPSecure = ‘false’; // set the SMTP port for the GMAIL server
$mail->Username = “[email protected]”; // SMTP account username
$mail->Password = “[email protected]!”;
$mail->setFrom(“[email protected]”, “gsure”);
$mail->Subject = $email_content[‘subject’];
$mail->MsgHTML($html);
$mail->addAddress($email_content[‘receipent_email’], “yellotasker”);
$mail->addAddress(“[email protected]”,”yellotasker”);
//$mail->addAttachment(‘/home/kundan/Desktop/abc.doc’, ‘abc.doc’); // Optional name
$mail->SMTPOptions= array(
‘ssl’ => array(
‘verify_peer’ => false,
‘verify_peer_name’ => false,
‘allow_self_signed’ => true
)
);
$mail->send();
//echo “success”;
} catch (phpmailerException $e) {

} catch (Exception $e) {

}
}