Reputation: 41
Anyone can help me please to solve this problem. Im trying to send PDF attachment with CakePHP. I think all thing should be work fine. But why I get email result like in screenshoot?
My code to send pdf:
function send_notif_email($email=null,$template='default',$data=null,$subject='Notification',$noreplay=true,$attachment=array()) {
$Email = new CakeEmail('default');
$emailData = $data;
if($Email->template($template)
->emailFormat('html')
->to($email)
->from(($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'))
->replyTo(($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'))
->setHeaders(array(
'From' => ($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'),
'Reply-To' => ($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'),
'MIME-Version' => '1.0',
'Content-type' => 'text/html; charset=iso-8859-1',
))
->attachments($attachment)
->subject($subject)
->viewVars(compact('emailData')) /*set data*/
->send()) {
return true;
}
return false;
}
I just check all attachment array and filepath, all is fine:
array(
'penawaran_0001_VN_SPN_X_2015' => '/home3/salesku/public_html/penawaran-online/app/webroot/upload/offer/00001/penawaran_0001_VN_SPN_X_2015.pdf',
'X100.pdf' => '/home3/salesku/public_html/penawaran-online/app/webroot/upload/attachment/00001/X100.pdf'
)
Thanks for help.
Upvotes: 0
Views: 585
Reputation: 41
I think I just found the problem. It looks likely setHeader should removed from method send_notif_email.
Not its work with new code:
function send_notif_email($email=null,$template='default',$data=null,$subject='Notification',$noreplay=true,$attachment=array()) {
$Email = new CakeEmail('default');
$emailData = $data;
if($Email->template($template)
->emailFormat('html')
->to($email)
->from(($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'))
->replyTo(($noreplay == true)?Configure::read('Meta.noreplay'):Configure::read('Meta.email'))
->attachments($attachment)
->subject($subject)
->viewVars(compact('emailData')) /*set data*/
->send()) {
return true;
}
return false;
}
Thanks for all.
Upvotes: 1