laravel mail

50

/**
 *  Send Mail from Parts Specification Form
 */
public function sendMail(Request $request) {
    $data = $request->all();

    $messageBody = $this->getMessageBody($data);

    Mail::raw($messageBody, function ($message) {
        $message->from('[email protected]', 'Learning Laravel');
        $message->to('[email protected]');
        $message->subject('Learning Laravel test email');
    });

    // check for failures
    if (Mail::failures()) {
        // return response showing failed emails
    }

    // otherwise everything is okay ...
    return redirect()->back();
}
Mail::to($email)
    ->cc(['[email protected]','[email protected]'])
    ->send(new document());
<?php
 
namespace App\Mail;
 
use App\Models\Order;
use Illuminate\Bus\Queueable;
use Illuminate\Mail\Mailable;
use Illuminate\Queue\SerializesModels;
 
class OrderShipped extends Mailable
{
    use Queueable, SerializesModels;
 
    /**
     * The order instance.
     *
     * @var \App\Models\Order
     */
    protected $order;
 
    /**
     * Create a new message instance.
     *
     * @param  \App\Models\Order  $order
     * @return void
     */
    public function __construct(Order $order)
    {
        $this->order = $order;
    }
 
    /**
     * Build the message.
     *
     * @return $this
     */
    public function build()
    {
      	// if only 1 file
        return $this->view('emails.orders.shipped')->attach($this->order['invoice']);
      
      	// if multiple files then i use this code
        return $this->view('emails.orders.shipped');
      	foreach ($this->order['invoice'] as $file){
            $this->attach($file);
        }
    }
}
// Please do comment if you have a better approach
// We all here to find shorter and faster way to get things done
// Thank you

Comments

Submit
0 Comments