[英]Cannot send email attachment PDF with CakePHP Mail
Anyone can help me please to solve this problem. 任何人都可以帮助我解决这个问题。 Im trying to send PDF attachment with CakePHP. 我试图用CakePHP发送PDF附件。 I think all thing should be work fine. 我认为一切都应该正常。 But why I get email result like in screenshoot? 但是,为什么我会在屏幕截图中得到电子邮件结果?
My code to send pdf: 我发送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. 感谢帮助。
I think I just found the problem. 我想我才发现问题。 It looks likely setHeader should removed from method send_notif_email. 似乎应该将setHeader从方法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. 谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.