如何使用 html 在 sendgrid 消息中添加 link

how to add link in sendgrid message using html

我想在 sendgrid

中使用电子邮件发送 link
$html =  'click on this   <a href="' . current_url . site_url("/users/verfication?code=" . $code)  . '">link</a>  to verify your account';

但它只是发送纯文本而不是渲染 link 如下消息

click on this   <a href="//users/verfication code=283add227e43e2674980ce9bbcd34833">link</a> 
  to verify your account


$CI->email->to($to);
        $CI->email->subject($sub);
        $CI->email->message($html);
        $CI->email->send();
}

您可以使用PHP函数preg_replace。使用正则表达式检测 link 并用相同的 link 替换 <a>.

更多信息:http://php.net/manual/en/function.preg-replace.php 这也应该有所帮助:Replace URLs in text with HTML links

您需要在电子邮件库中传递配置,并且需要将电子邮件类型指定为html

$config = Array(
    'mailtype' => 'html',
    ...etc...
);
$this->load->library('email', $config);