Answers for "local sendmail laravel"

PHP
1

phpmailer with laravel

<?php
namespace App\Http\Controllers;

use PHPMailer\PHPMailer;

class testPHPMailer extends Controller
{
    public function index()
    {
        $text             = 'Hello Mail';
        $mail             = new PHPMailer\PHPMailer(); // create a n
        $mail->SMTPDebug  = 1; // debugging: 1 = errors and messages, 2 = messages only
        $mail->SMTPAuth   = true; // authentication enabled
        $mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for Gmail
        $mail->Host       = "smtp.gmail.com";
        $mail->Port       = 465; // or 587
        $mail->IsHTML(true);
        $mail->Username = "[email protected]";
        $mail->Password = "testpass";
        $mail->SetFrom("[email protected]", 'Sender Name');
        $mail->Subject = "Test Subject";
        $mail->Body    = $text;
        $mail->AddAddress("[email protected]", "Receiver Name");
        if ($mail->Send()) {
            return 'Email Sended Successfully';
        } else {
            return 'Failed to Send Email';
        }
    }
}
Posted by: Guest on April-08-2021
0

laravel send email

//  admin.newsletters.send_email : is the blade that will have your email content
  // 'newsletter' => $newsletter : is the collection to be used in the blade file
  // function ($message) : the function email and the variable to be used in the message.
//  use ($newsletter) : is the collection to be used in the message controller (e.g $message->to($newsletter->email))
  // Swift_TransportException to check if it is real email


namespace App\Http\Controllers\Admin;
use Mail;

      public function sendEmail(Newsletter $newsletter)
    {

try {          
  Mail::send('admin.newsletters.send_email', ['newsletter' => $newsletter], function ($message) use ($newsletter) {
    $message->from('[email protected]', 'eee-services.com');

    $message->to('[email protected]')->subject('Newsletter');
  });
      } catch (\Swift_TransportException $e) {
        if ($e->getMessage()) {
          return redirect()->route('admin.newsletters.index');
        }
      }

  return redirect()->route('admin.newsletters.index');
  }
Posted by: Guest on August-25-2021

Browse Popular Code Answers by Language