Sending email message by adding cc and fields in codeigniter php
Hi, contact us. I send emails to other IDs by adding them to CC, but when I send email, all emails show up in the "TO" option, the mail IDs I mentioned in CC should only show up in CC, but it gets combed with the email id. How to distinguish between letters TO and CC.
function send_mails($email)
{
$name = $this->input->post('fullname');
$from_email = $this->input->post('email');
$phone = $this->input->post('phone');
$description = $this->input->post('text');
$subject=$this->input->post('subject');
//set to_email id to which you want to receive mails
$to_email = 'example@gmail.com';
$config=Array(
'protocol'=> 'smtp',
'smtp_host' => 'ssl://smtp.gmail.com', //smtp host name
'smtp_port' => '465', //smtp port number
'smtp_user' => 'XXX@gmail.com',
'smtp_pass' => 'YYYY', //$from_email password
'mailtype' =>'html',
'newline' =>"\r\n",
'crlf' =>"\r\n",
'charset' => 'iso-8859-1',
'wordwrap' => TRUE
);
$message = array();
$message[] = 'Username : '.trim($name).' ';
$message[] = 'Phone Number : '.trim($phone).' ';
$message[] = 'Description : '.trim($description).' ';
$message = implode(PHP_EOL, $message);
//send mail
$this->load->library('email',$config);
$this->email->from($from_email);
$this->email->to($to_email);
$this->email->cc('info@gmail.com,xyz@gmail.com');
$this->email->subject($subject);
$this->email->message($message);
$this->email->set_newline("\r\n");
if ($this->email->send())
{
$this->flash->success('Thank you for contacting us we will get back to you soon!</div>');
redirect('contact');
}
else
{
$this->flash->success('There is error in sending mail! Please try again later');
redirect('contact');
}
}
Here, in the TO address, there is only one email ID that should only appear in the TO field. And there are two email IDs in CC that both should display in cc.
+3
source to share
1 answer
Try using an array when doing cc.
$this->load->library('email',$config);
$this->email->from($from_email);
$this->email->to($to_email);
$list = array('one@example.com', 'two@example.com', 'three@example.com');
$this->email->cc($list);
$this->email->subject($subject);
$this->email->message($message);
$this->email->set_newline("\r\n");
Please try this and let me know if you still have the same error.
+3
source to share