skip to Main Content

I need to send some test emails from Laravel and want to do it, without Mail classes, etc. I usually use the Mail::send() function for this and it works fine. However, I’ve just realized that cc/bcc recipients don’t seem to work when using this form.

In case useful to know, I’m using sendmail.

$result=Mail::send('site.emails.empty-template', ['msg'=>"Hi this is a test msg"], function ($message) {
    $message->from('[email protected]');
    $message->subject("A test email");
    $message->to("[email protected]");
    $message->cc("[email protected]");
    $message->bcc(["[email protected]","[email protected]]);
});

3

Answers


  1. Did you try like this:

    Mail::to($email)
        ->cc(['[email protected]','[email protected]'])
        ->send('something');
    
    Login or Signup to reply.
  2. You can use Mail::send method, and by using this, you can customize your subject and body.

    $options = [
        'cc' => '[email protected]',
        'bcc' => ['[email protected]', '[email protected]'],
    ];
    
    Mail::send([], [], function ($message) use ($email, $options) {
        $message->to($email)
                ->cc($options['cc'])
                ->bcc($options['bcc'])
                ->subject('A test emai')
                ->setBody('This is the email content.', 'text/html');
    });
    
    

    OR

    you may use this one

    Create a new mailable class

     php artisan make:mail MyMail
    
    class MyMail extends Mailable
    {
        use Queueable, SerializesModels;
    
        public function __construct()
        {
            //
        }
    
        public function build()
        {
            return $this->view('emails.my-email')
                        ->cc(['[email protected]']);
        }
    }
    

    Use class to send the email

     Mail::to($email)->send(new MyMail());
    
    Login or Signup to reply.
  3. In bcc there’s an " closing issue:

    $result=Mail::send('site.emails.empty-template', ['msg'=>"Hi this is a test msg"], function ($message) {
        $message->from('[email protected]');
        $message->subject("A test email");
        $message->to("[email protected]");
        $message->cc("[email protected]");
        
        // $message->bcc(["[email protected]","[email protected]]);
        $message->bcc(["[email protected]","[email protected]"]);
    });
    

    Note: For multiple emails you’ve to pass array

    You can visit these links as a reference:

    Send e-mail without implementing a Mailable class #41632

    Laravel send email without Mailable

    You can also try like this:

    Mail::send([], [], function ($message) {
      $message->to("[email protected]")
        ->subject("A test email")
        ->cc("[email protected]")
        ->bcc(["[email protected]","[email protected]"])
        // here comes what you want
        ->setBody('Hi Adam'); // assuming text/plain
        // or:
        ->setBody('<h1>Hi Adam</h1>', 'text/html'); // for HTML rich messages
    });
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search