php mail sending script

the mail() function

Moderators: egami, macek, gesf

Post Reply
eXPlosion
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 13, 2017 12:06 am

Mon Mar 13, 2017 12:48 am

here is mail controller class

Code: Select all

    <?php
    
    namespace App\Http\Controllers;
    
    use Illuminate\Http\Request;
    use App\Http\Requests;
    use App\Http\Controllers\Controller;
    use App\MassMail;
    use App\Contact;
    use Illuminate\Support\Facades\Auth;
    use Mail;
    
    class MassMailController extends Controller
    {
        public function index()
        {
            $mails = MassMail::orderBy('date_sent', 'DESC')->get();
            return view('mail.mass.index')->with('mails', $mails);
        }
    
        public function show($id)
        {
            $mail = MassMail::findOrFail($id);
            return view('mail.mass.show')->with('mail', $mail);
        }
    
        public function create()
        {
            $movies = Auth::user()->movies()->lists('title', 'id');
    
            return view('mail.mass.create')->with('movies', $movies);
        }
    
        public function send(Requests\EmailTemplateRequest $request)
        {
            $emails = Contact::whereNotNull('email')->lists('email')->toArray();
    
            Mail::send(['text' => 'emails.plain'], ['text' => $request->message], function ($message) use ($request, $emails) {
                $message->from('info@someone.com', $request->sender);
                $message->subject($request->subject);
                $message->to($emails);
            });
            //send
            $mail = new MassMail($request->all());
            $mail->date_sent = \Carbon\Carbon::now();
            $mail->recipent_count = count($emails);
            \Auth::user()->massMail()->save($mail);
            $contacts = Contact::whereNotNull('email')->lists('id')->toArray();
            foreach($contacts as $contact){
                $mail->recipents()->attach($contact);
            }
            return redirect('mail/mass');
        }
    
    }
There is a requirement that multiple receivers won't see other receivers. Like blind copy. How to modify it?
Thanks.
There is also mass mail class, which looks like this:

Code: Select all

    <?php
    
    namespace App;
    
    use Illuminate\Database\Eloquent\Model;
    
    class MassMail extends Model
    {
        /**
         * The table associated with the model.
         *
         * @var string
         */
        protected $table = 'mass_mails';
    
        protected $fillable = [
            'sender',
            'subject',
            'message',
            'movie_id'
        ];
    
        public $timestamps = false;
    
        public function recipents()
        {
            return $this->belongsToMany('App\Contact', 'contact_mass_mail_pivot', 'mass_mail_id', 'contact_id');
        }
    }
Any ideas?

eXPlosion
New php-forum User
New php-forum User
Posts: 2
Joined: Mon Mar 13, 2017 12:06 am

Mon Mar 13, 2017 4:52 am

I'm wondering would it work if i change

Code: Select all

 $message->to($emails);
to

Code: Select all

$message->bcc($emails);

Post Reply