简体   繁体   中英

send email with attachment in cakephp

i want to send email with some attachment in cakephp.

here is my code:

 $Email = new CakeEmail('default');
    $Email->from(array('info@test.com' => $message['Message']['subject']))
        ->to($email)
        ->sender(array('info@test.com' => $message['Message']['subject']))
        ->replyTo(array('info@test.com' => $message['Message']['subject']))
        ->subject($message['Message']['subject'])
        ->attachments(array(
            1 => 'http://test.com/files/message_file/file/9/56b22b15b3cec.jpg'
        ))
        ->send($message['Message']['description']);

but i face to this error when i run it:

File not found: " http://test.com/files/message_file/file/9/56b22b15b3cec.jpg " Error: An Internal Error Has Occurred.

Use sever absolute path to file for attachment

$Email
      ->attachments(array(
            1 =>  WWW_ROOT . 'files' . DS. 'message_file' . DS . 'file'.DS.'9'.DS.'56b22b15b3cec.jpg'
        ))

您需要使用文件系统路径而不是附件的URL。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM