2

In the user manual of Codeigniter's Email Library, under Email Function Reference, wer see $this->email->from() with two parameters: an email address as well as as 'Your Name' that is set as the second parameter.

But when it comes to $this->email->to(), we cannot set the recipient's name. While we can see that in the real world (eg. gmail), the request has been answered as it's expected.

4

3 回答 3

2

不幸的是,函数to()不提供任何设置收件人姓名的方法。

但是,您可以扩展Email该类并手动添加附加功能,例如设置名称。

否则,您可能应该使用其他工具来发送电子邮件。例如PHPMailer.

于 2013-06-13T00:00:46.950 回答
2

不要浪费时间尝试使用以下代码传递收件人的姓名:

 $this->email->to('John Smith <john@example.com>');

因为to()函数清除所有使用 clean_email() 传递的参数

    public function to($to)
    {
        $to = $this->_str_to_array($to);
        $to = $this->clean_email($to);
    // ...



/**
 * Clean Extended Email Address: Joe Smith <joe@smith.com>
 *
 * @access  public
 * @param   string
 * @return  string
 */
public function clean_email($email)
{
    if ( ! is_array($email))
    {
        if (preg_match('/\<(.*)\>/', $email, $match))
        {
            return $match['1'];
        }
        else
        {
            return $email;
        }
    }
    // ...
于 2013-06-13T00:00:55.863 回答
1

我刚刚发现了绕过 Codeigniter 中的清理过程的技巧。$this->email->to()您应该手动设置电子邮件标题,而不是使用。

$this->email->set_header('To', '"' . $recipient_display_name . '" <'. $recipient_email . '>');

我还没有测试过提供收件人电子邮件列表,但我认为这个想法是一样的。

于 2018-07-19T23:41:41.110 回答