如何使用 smtp 向 codeigniter 中的多个收件人发送电子邮件?
How to send email to multiple recipients in codeigniter using smtp?
嗨,朋友们,我正在 codeigniter.In 此代码中创建使用 SMTP 服务器发送电子邮件,我正在尝试向客户、e_commerce、帐户和分支机构发送电子邮件。它只发送给客户。
$order_number = $data['order_number'];
$order['order'] = $this->Checkout_model->get_order_details($order_number);
$branch_id = $this->Checkout_model->getbranch_id($data['order_number']);
$branch_email = $this->Checkout_model->getbranch_email($branch_id);
$mesg = $this->load->view('mail/email_order', $order, true);
$customer_email = $response['customer_email'];
$ecommerce_email = 'codeqtechnology06@gmail.com';
$account_email ='arpitsingh791@outlook.com';
$list = array($customer_email, $ecommerce_email, $account_email, $branch_email);
$mail_count= count($list);
for($i=0;$i<$mail_count;$i++)
{
$this->load->library('email');
$config=array(
'protocol' => 'smtp',
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html',
'smtp_host' => 'mail.xxxxx.com',
'smtp_user' =>'sales@xxxx.com',
'smtp_pass' =>'sales',
'smtp_port' =>xy,
'smtp_timeout' => 30,
);
$mail_id = $list[$i];
$this->email->initialize($config);
$this->email->from('sales@xxxx.com', 'ABC Order');
$this->email->to($mail_id);
$this->email->bcc('arpitsingh791@gmail.com');
$this->email->subject('Order : '.$order_number);
$this->email->message($mesg);
$this->email->send();
$this->email->clear();
}
您不需要循环,如果您需要,则不应在循环内加载和初始化电子邮件 class。
我假设您显示的所有设置(以及您未显示的设置)都为所有变量生成了正确的值。 (如果不是,则所有投注均无效。)
这个解决方案利用了这样一个事实,即您可以为 Email::bcc()
方法提供一个地址数组。通过这样做,您可以一次性向所有感兴趣的各方发送电子邮件。
您最好使用 /application/config/email.php 来提供配置。下面我使用了您的配置数组,但我将其传递给电子邮件构造函数。这样就不需要调用 $this->email->initialize($config);
。
$order_number = $data['order_number'];
$order['order'] = $this->Checkout_model->get_order_details($order_number);
$branch_id = $this->Checkout_model->getbranch_id($data['order_number']);
$branch_email = $this->Checkout_model->getbranch_email($branch_id);
$mesg = $this->load->view('mail/email_order', $order, true);
$customer_email = $response['customer_email'];
$ecommerce_email = 'codeqtechnology06@gmail.com';
$account_email = 'arpitsingh791@outlook.com';
$bcc_list = array('arpitsingh791@gmail.com', $ecommerce_email, $account_email, $branch_email);
$config = array(
'protocol' => 'smtp',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'mailtype' => 'html',
'smtp_host' => 'mail.xxxxx.com',
'smtp_user' => 'sales@xxxx.com',
'smtp_pass' => 'sales',
'smtp_port' => xy,
'smtp_timeout' => 30,
);
$this->load->library('email', $config);
$this->email
->from('sales@xxxx.com', 'ABC Order')
->to($customer_email)
->bcc($bcc_list)
->subject('Order : '.$order_number)
->message($mesg)
->send();
嗨,朋友们,我正在 codeigniter.In 此代码中创建使用 SMTP 服务器发送电子邮件,我正在尝试向客户、e_commerce、帐户和分支机构发送电子邮件。它只发送给客户。
$order_number = $data['order_number'];
$order['order'] = $this->Checkout_model->get_order_details($order_number);
$branch_id = $this->Checkout_model->getbranch_id($data['order_number']);
$branch_email = $this->Checkout_model->getbranch_email($branch_id);
$mesg = $this->load->view('mail/email_order', $order, true);
$customer_email = $response['customer_email'];
$ecommerce_email = 'codeqtechnology06@gmail.com';
$account_email ='arpitsingh791@outlook.com';
$list = array($customer_email, $ecommerce_email, $account_email, $branch_email);
$mail_count= count($list);
for($i=0;$i<$mail_count;$i++)
{
$this->load->library('email');
$config=array(
'protocol' => 'smtp',
'charset'=>'utf-8',
'wordwrap'=> TRUE,
'mailtype' => 'html',
'smtp_host' => 'mail.xxxxx.com',
'smtp_user' =>'sales@xxxx.com',
'smtp_pass' =>'sales',
'smtp_port' =>xy,
'smtp_timeout' => 30,
);
$mail_id = $list[$i];
$this->email->initialize($config);
$this->email->from('sales@xxxx.com', 'ABC Order');
$this->email->to($mail_id);
$this->email->bcc('arpitsingh791@gmail.com');
$this->email->subject('Order : '.$order_number);
$this->email->message($mesg);
$this->email->send();
$this->email->clear();
}
您不需要循环,如果您需要,则不应在循环内加载和初始化电子邮件 class。
我假设您显示的所有设置(以及您未显示的设置)都为所有变量生成了正确的值。 (如果不是,则所有投注均无效。)
这个解决方案利用了这样一个事实,即您可以为 Email::bcc()
方法提供一个地址数组。通过这样做,您可以一次性向所有感兴趣的各方发送电子邮件。
您最好使用 /application/config/email.php 来提供配置。下面我使用了您的配置数组,但我将其传递给电子邮件构造函数。这样就不需要调用 $this->email->initialize($config);
。
$order_number = $data['order_number'];
$order['order'] = $this->Checkout_model->get_order_details($order_number);
$branch_id = $this->Checkout_model->getbranch_id($data['order_number']);
$branch_email = $this->Checkout_model->getbranch_email($branch_id);
$mesg = $this->load->view('mail/email_order', $order, true);
$customer_email = $response['customer_email'];
$ecommerce_email = 'codeqtechnology06@gmail.com';
$account_email = 'arpitsingh791@outlook.com';
$bcc_list = array('arpitsingh791@gmail.com', $ecommerce_email, $account_email, $branch_email);
$config = array(
'protocol' => 'smtp',
'charset' => 'utf-8',
'wordwrap' => TRUE,
'mailtype' => 'html',
'smtp_host' => 'mail.xxxxx.com',
'smtp_user' => 'sales@xxxx.com',
'smtp_pass' => 'sales',
'smtp_port' => xy,
'smtp_timeout' => 30,
);
$this->load->library('email', $config);
$this->email
->from('sales@xxxx.com', 'ABC Order')
->to($customer_email)
->bcc($bcc_list)
->subject('Order : '.$order_number)
->message($mesg)
->send();