我想在 cakephp 的电子邮件中插入 link

I want to insert a link in an email in cakephp

我想给用户发送邮件,邮件正在发送,但是里面的link现在显示为link,我也想在邮件中嵌入一个标志但是徽标未显示,下面是我的代码。我正在使用蛋糕 2.8

$Email = new CakeEmail();
   $Email->from(array('admin@wacscoac.org'=>'West Africal College of Surgeons'));
   $Email->to($email);
   $Email->subject('Reviewer Invitation From West African College of Surgeons');
   $Email->send('Dear Reviewer, You have been invited by the Head of Faculty  of $faculty from the West'
           . 'African College of Surgeons to register as a reviewer. Please click on the link '
           . 'below to register'
           . 'http://wacscoac.org/edms/users/addreviewer');
   $Email->attachments('img/logo.png');  

我个人认为我会使用 HTML 标签

<a href = "site you desire">Link tage</a>

但请记住,您需要设置

$headers .= "Content-type: text/html\r\n";

求邮件,祝你好运。

$link = '<a href="http://wacscoac.org/edms/users/addreviewer"'>
             <img src="img/logo.png" alt="">
        </a>';

然后

$Email->send('Dear Reviewer, You have been invited by the Head of aculty  of $faculty from the West'  
           . 'African College of Surgeons to register as a reviewer. Please click on the link '
           . 'below to register'
           . $link);

假设您希望徽标也是 link:

我认为最好的方法是使用模板,这样您就可以在 .ctp 文件中使用 Html 帮助程序

$Email->attachments(['img/logo.png'=> [
    'file' => 'img/logo.png',
    'mimetype' => 'image/png',
    'contentId' => 'logo'
]]);
$Email->template('test');
$Email->emailFormat('html');
$Email->viewVars(array(
    'faculty' => "Faculty",
));
$Email->send();

如果您希望内嵌附件,指定 contentId 很有用,如手册 here

中所述

之后您必须在 \src\Template\Email\html\test.ctp

中创建模板
<p>Dear Reviewer,</p> 

<p>You have been invited by the Head of Faculty  of <?= $faculty ?> 
from the West African College of Surgeons to register as a reviewer.</p>

<p>Please click on the link below to register</p>

<?= $this->Html->link(
        '<img src="cid:logo" alt="">',         
        'http://wacscoac.org/edms/users/addreviewer', 
        ['escape' => false]); 
?>