繁体   English   中英

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

[英]Sending an email by adding cc and to fields in codeigniter php

嗨,与我们联系,我通过在 CC 中添加邮件来将邮件发送到不同的 ID,但是在发送电子邮件时,所有电子邮件都显示在“TO”选项中,我在 CC 中提到的邮件 ID 应该只显示在 CC 中,但它正在梳理与 To email id.How 区分 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 应仅显示在 TO 字段中。 在 CC 中有两个电子邮件 ID,它们都应该显示在 cc 中。

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

请尝试此操作,如果您仍然遇到相同的错误,请告诉我。

      $this->email->initialize(array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.gmail.com',
        'smtp_user' => 'email',
        'smtp_pass' => 'pwd',
        'smtp_port' => 490,
        'crlf' => "\r\n",
        'newline' => "\r\n"
      ));


$this->email->from('email', 'name');
$this->email->to($to);
$this->email->cc($cc);
$this->email->bcc('email');
$this->email->subject('Email Test');
$this->email->message('Testing the email class.');
$this->email->send();

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM