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

标签 php codeigniter email

您好,联系我们,我通过在 CC 中添加它们来向不同的 ID 发送邮件,但是在发送电子邮件时,所有电子邮件都显示在“收件人”选项中,我在 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');
        }
}

在收件人地址中,只有一个电子邮件 ID 应仅显示在收件人字段中。 在 CC 中有两个电子邮件 ID,它们都应该显示在 cc 中。

最佳答案

在做cc的时候尽量使用array。

$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");

请试试这个,如果您仍然遇到同样的错误,请告诉我。

关于php - 通过在 codeigniter php 中添加 cc 和字段来发送电子邮件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44449940/

相关文章:

c# - 如何通过指定发件人地址使用 Microsoft.Office.Interop.Outlook.MailItem 发送邮件

php - $this->app->singleton() 在 Laravel 中是如何工作的?

php - 在 CodeIgniter 中,如何使用分页参数从 Controller 调用 ajax url

php - 如何在 Codeigniter 3 中连接到 POSTGRESQL?

php - codeigniter 3 中无法发送电子邮件 SMTP 错误

java - Java 中的 IMAP 客户端 : JavaMail API or Apache Commons Net?

php - 如何确定我的 sql 查询是否为 Null?

php - 如何删除php中的一些单词

php - 如何在Woocommerce中检查产品是否具有特定的产品属性

php - 将 MySQL 数据库连接到 InfusionSoft 联系人