Zahra Badri
Zahra Badri

Reputation: 2034

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('[email protected]' => $message['Message']['subject']))
        ->to($email)
        ->sender(array('[email protected]' => $message['Message']['subject']))
        ->replyTo(array('[email protected]' => $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.

Upvotes: 2

Views: 2836

Answers (2)

Nabin  Nembang
Nabin Nembang

Reputation: 753

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'
        ))

Upvotes: 4

ADmad
ADmad

Reputation: 8100

You need to use a filesytem path not URL for attachments.

Upvotes: 2

Related Questions