添加附件以自动回复联系表格7

时间:2018-04-01 09:32:47

标签: php html wordpress plugins contact-form-7

是否可以将PDF添加到人们将收到的CF7自动应答器中?

我尝试过使用邮件2中的附件字段,但它似乎没有附加任何内容。从我的研究看来,这个功能似乎被窃听了?即使路径正确,它也说错误的路径。

我尝试使用以下代码,但没有运气



add_action( 'wpcf7_before_send_mail', 'send_attachment_file' );
 function send_attachment_file($cf7)
 {
 //check if this is the right form
 
if ($cf7->id==872)        // This is the form ID
 {
 $uploads = wp_upload_dir();     // will output the array of path,url,subdir,basedir,baseurl,error -- what we need is the path = '/home/euroling/public_html/beta/wp-content/uploads/2013/01'
 //define some constants
 define ('PRICE_UPLOAD_PATH',$uploads['path'].'/price');     // create price folder in the path
 // ...
 // ...
 if ($cf7->mail['use_html']==true)
 $nl="<br/>";
 else
 $nl="\n";
 //I omitted all the stuff used to create
 //the pdf file, you have just to know that
 //$pdf_filename contains the filename to attach
 //Let'go to the file attachment!
 
// $pdf_filename with the extenstion not just the filename
 $pdf_filename = "testnew.pdf";
 $cf7->uploaded_files = array( 'file_upload' => PRICE_UPLOAD_PATH .'/'.$pdf_filename );
 
//append some text to the outgoing email
 $message=$nl.$nl.'Blah blah blah.....'.$nl;
 $message.='So Long, and Thanks for All the Fish!'.$nl;
 $cf7->mail_2['body'].=$message;
 }
}
&#13;
&#13;
&#13;

还可以根据填写的字段来决定附加哪个文件?我们有5个选项的下拉列表,我们需要根据所选的选项添加不同的PDF。

1 个答案:

答案 0 :(得分:1)

我的坏。似乎附件功能确实有效。有关详情,请参阅:https://contactform7.com/configuration-errors/file-not-found/

确保使用相对路径,例如:uploads / 2018/03 / Skarpeknive-gavekort.jpg