I found php code from stackoverflow for this, but it doesn't seem to be working with my form. It should be taking the submission results, adding them to variables, then placing them into a pdf document that is attached to the email sent from Contact Form 7.
I have added the code below to my theme's functions.php file. FPDF has also been extracted and placed into my theme's folder. When I submit the form on my website, the email comes through fine, but it doesn't have the pdf. If anyone could point me in the right direction, I would appreciate it.
add_action('wpcf7_before_send_mail', 'wpcf7_update_email_body');
function wpcf7_update_email_body($contact_form) {
$submission = WPCF7_Submission::get_instance();
if ( $submission ) {
/* DEFINE CONSTANT AND GET FPDF CLASSES */
define ('FPDF_PATH',get_template_directory().'/wp-content/themes/escapade/fpdf/'); // MAKE SURE THIS POINTS TO THE DIRECTORY IN YOUR THEME FOLDER THAT HAS FPDF.PHP
require(FPDF_PATH.'fpdf.php');
$posted_data = $submission->get_posted_data();
// SAVE FORM FIELD DATA AS VARIABLES
$name = $posted_data["your-name"];
$email = $posted_data["your-email"];
$message = $posted_data["your-message"];
$verifyeft = $posted_data["verifyeft"];
$expensecategory = $posted_data["expensecategory-892"];
$purpose = $posted_data["your-purpose"];
$pretax = $posted_data["pretax-837"];
$tax = $posted_data["tax-424"];
$totalamount = $posted_data["totalamount-101"];
$pdf = new FPDF();
$pdf->AddPage();
$pdf->SetFont('Arial','B',16);
$pdf->Write(5,$name . "
" . $email . "
" . $message . "
" . $verifyeft . "
" . $expensecategory . "
" . $purpose . "
" . $pretax . "
" . $tax . "
" . $totalamount);
$pdf->Output(FPDF_PATH.'test.pdf', 'F'); // OUTPUT THE NEW PDF INTO THE SAME DIRECTORY DEFINED ABOVE
}
}
add_filter( 'wpcf7_mail_components', 'mycustom_wpcf7_mail_components' );
function mycustom_wpcf7_mail_components($components){
if (empty($components['attachments'])) {
$components['attachments'] = array(FPDF_PATH .'expenseform.pdf'); // ATTACH THE NEW PDF THAT WAS SAVED ABOVE
}
return $components;
}