通过添加cc和发送到codeigniter php中的字段来发送电子邮件

时间:2017-06-09 05:31:55

标签: php codeigniter email

您好联系我们我通过在CC中添加邮件将邮件发送到不同的ID但在发送电子邮件时所有电子邮件都显示在" TO"选项我在CC中提到的邮件ID应该只显示在CC中,但是它与To email id结合。如何区分TO和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');
        }
}

此处在TO地址中,只有一个电子邮件ID应仅显示在“收件人”字段中。 在CC中,有两个电子邮件ID,它们都应以cc形式显示。

2 个答案:

答案 0 :(得分:4)

尝试在执行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");

请尝试此操作,如果您仍有同样的错误,请与我们联系。

答案 1 :(得分:0)

#fileInput