Jump to content

php mail sending script


eXPlosion

Recommended Posts

here is mail controller class

 



    <?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:

 



    <?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?

Link to comment
Share on other sites

Roughly speaking; Locate the emails of the recieving people and remove them, or simplie dont do email lists like : $email_to = "jhewitt@amleo.com,some@other.com,yet@another.net"; in the first place, im no expert in this but, if i would do that, i would create a simple mail funktion and an for each loop that reads an array with all the recievers and then sends them by triggering the function

you might use http://php.net/manual/de/class.thread.php if you have a massive ammount of emails.   

 

Link to comment
Share on other sites

I don't know what actual mail command you are using or what mailing package, but usually the bcc: is setup in the header of the email being sent. Check out the simple PHP "mail()" function in the official php manual to see what the headers should have in them.

  • Like 1
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.