2016-06-21 25 views
0

我想發送郵件給用戶,郵件正在發送,但其中的鏈接現在顯示爲鏈接,我還希望在郵件中嵌入徽標但徽標沒有顯示,下面是我的代碼。我使用的蛋糕2.8我想在cakephp中的電子郵件中插入一個鏈接

$Email = new CakeEmail(); 
    $Email->from(array('[email protected]'=>'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'); 

回答

3

假設你想要的標誌,也鏈接:

我認爲最好的方法是使用模板,以便您可以使用HTML幫助中的.ctp文件

$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]); 
?> 
0

在我自己看來,我會使用HTML標籤

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

但請記住,你需要設置

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

的電子郵件,祝你好運。

0
$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); 
+0

創建模板@ AIPD TECH,謝謝你,但是這是我得到錯誤的錯誤:在調用一個成員函數的圖像()非對象 –

+0

謝謝,但如果logo.png位於webroot文件夾中呢? –

+0

只需從路徑中刪除'img'。我會建議使用模板發送電子郵件。 '$的電子郵件 - > emailFormat( 'HTML');' –

相關問題