【问题标题】:I want to insert a link in an email in cakephp我想在 cakephp 的电子邮件中插入一个链接
【发布时间】:2016-06-21 09:18:41
【问题描述】:

我想向用户发送邮件,邮件正在发送,但其中的链接现在显示为链接,我还想在邮件中嵌入徽标但徽标未显示,下面是我的代码.我正在使用蛋糕 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');  

【问题讨论】:

    标签: php cakephp cakephp-3.0 cakephp-2.3


    【解决方案1】:

    假设您希望徽标也是链接:

    我认为最好的方法是使用模板,这样您就可以在 .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]); 
    ?>
    

    【讨论】:

      【解决方案2】:

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

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

      但请记住,您需要设置

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

      对于电子邮件,祝你好运。

      【讨论】:

        【解决方案3】:
        $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);
        

        【讨论】:

        • @AIPD TECH,谢谢,但这是我得到的错误 Error: Call to a member function image() on a non-object
        • 谢谢,但是如果 logo.png 在 webroot 文件夹中呢?
        • 只需从路径中删除img。我会建议使用模板发送电子邮件。 $Email-&gt;emailFormat('html');
        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2016-10-09
        • 2017-10-21
        • 1970-01-01
        • 2018-11-01
        • 2018-03-25
        • 1970-01-01
        相关资源
        最近更新 更多