【问题标题】:Sending an email by adding cc and to fields in codeigniter php通过在 codeigniter php 中添加 cc 和字段来发送电子邮件
【发布时间】:2017-11-11 00:11:42
【问题描述】:

您好,联系我们,我通过将邮件添加到 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 应仅显示在 TO 字段中。 在抄送中有两个电子邮件 ID,它们都应该在抄送中显示。

【问题讨论】:

    标签: php codeigniter email


    【解决方案1】:

    在做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-&gt;email-&gt;set_mailtype("html"); 并使用Html &lt;br&gt; 进入另一行。
    • 将消息存储在数组中并在消息字段中传递该数组,您可以在我的代码中查看
    • 使用$message = implode('&lt;br&gt;', $message);
    【解决方案2】:
          $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();
    

    【讨论】:

      猜你喜欢
      • 2021-06-23
      • 2015-05-12
      • 2012-05-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-03-22
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多