Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
848 views
in Technique[技术] by (71.8m points)

php - Sending mail to multiple recipients with sendgrid and codeigniter

I recently signed up for SendGrid and took a look at their integration into CodeIgniter.

They recommend doing the following to send mail out:

 $this->email->initialize(array(
      'protocol' => 'smtp',
      'smtp_host' => 'smtp.sendgrid.net',
      'smtp_user' => 'sendgridusername',
      'smtp_pass' => 'sendgridpassword',
      'smtp_port' => 587,
      'crlf' => "
",
      'newline' => "
"
    ));

    $this->email->from('[email protected]', 'Your Name');
    $this->email->to('[email protected]');
    $this->email->cc('[email protected]');
    $this->email->bcc('[email protected]');
    $this->email->subject('Email Test');
    $this->email->message('Testing the email class.');
    $this->email->send();

    echo $this->email->print_debugger();

This seems like a nice solution for sending out emails to single individuals but what if I have an email that I want to send to a whole bunch of people? Is it possible to send either the "to" or the "bcc" in as an array?

Is there a different integration method preferred for using SendGrid with CI?

Thanks!

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

You can use it in the normal way. You can pass an array of email addresses or a comma separated string of email addresses.

Like

$list = array('[email protected]', '[email protected]', '[email protected]');
// or
//$list = '[email protected], [email protected], [email protected]';

$this->email->to($list);
// or
//$this->email->cc($list);
// or
//$this->email->bcc($list);

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...