2012-08-17 123 views
0

我正在努力發送帶有附件的電子郵件。 我使用php默認配置發送電子郵件,但使用CakePHP框架。如何使用CakePHP 1.3發送帶附件的電子郵件?

$fromEmail = $from_name." <".$from_email.">"; 
$this->Email->from = $fromEmail; 
$this->Email->to = trim($email); 
$this->Email->subject = $subjects[$this->params['action']]; 
$this->Email->sendAs = 'text'; 
$this->Email->template = $this->params['action']; 
print_r($attachments); exit; // Gave me an empty Array () 
$this->Email->attachments = $attachments; 

$attachments = array(); 
      if (! empty($this->data['Submit']['files'])) { 
       $attach_files = $this->Document->DocumentDocument->find('all', array(
        'conditions' => array(
         'MailDocument.Mail_id' => $this->data['Submit']['prop_id'], 
         'MailDocument.id' => $this->data['Submit']['files'], 
        ), 
       )); 
       $attachments = Set::combine($attach_files, '/PropertyDocument/file', '/PropertyDocument/file_path'); 
      } 

我知道我們必須在cakePHP中定義文件路徑。

我哪裏錯了?

回答

2

您設置了一個數組,其中包含要附加到組件的附件屬性的文件的路徑。

$this->Email->attachments = array(
    TMP . 'att.doc', 
    'att2.doc' => TMP . 'some-name' 
); 

第一個文件att.doc將附加相同的文件名。對於第二個文件,我們指定一個別名att2.doc將用於附加,而不是其實際文件名some-name

+0

讓我試試看。 – Karma 2012-08-17 07:15:30

+0

謝謝:)我做了類似的線路。有效。 :) – Karma 2012-08-17 07:26:11

相關問題