This page was exported from Wordpress Joomla Freelancer Web Designer Web Developer Mumbai [ http://www.santoshkori.com/blog ]
Export date: Wed Dec 19 16:20:28 2018 / +0000 GMT

How to send pdf file attachment to user using contact form 7



Here is code to send pdf file attachment to user using contact form 7.

[php]

function send_pdf( $cf7 ) {

$id = $cf7->id();

if ($id==1076){

$submission = WPCF7_Submission::get_instance();

$posted_data = $submission->get_posted_data();

$tdsfileurl = $posted_data['tdsfile'];

$tdsproductname = $posted_data['productname'];

$explode = explode("/", $tdsfileurl);

$end = '';

$begin = '';

if(count($explode) > 0){

$end = array_pop($explode); // removes the last element, and returns it

if(count($explode) > 0){

$begin = implode('/', $explode); // glue the remaining pieces back together

}

}

$t=time();

$hostname = $_SERVER['HTTP_HOST'];

$newfile2 = explode($hostname, $begin);

$newfile = $_SERVER['DOCUMENT_ROOT'] . '' .$newfile2['1'].'/' .$tdsproductname.'_TDS_'.$t.'.pdf';

error_log('$tdsfileurl: ' . $tdsfileurl);

error_log('$newfile: ' . $newfile);

if ( copy($tdsfileurl, $newfile) ) {

error_log('File copied');

$submission->add_uploaded_file('pdf', $newfile);

}else{

error_log('Not able to attche file');

}

}

}

add_action('wpcf7_before_send_mail','send_pdf');

[/php]

1076 is contact form 7 ID and tdsfile form field is having PDF url form local server (http://localhost:90/pidi/wp-content/uploads/2015/09/test.pdf) which i want to send as attachment.

 

 


Post date: 2016-02-10 20:36:21
Post date GMT: 2016-02-10 11:36:21
Post modified date: 2016-02-10 20:36:36
Post modified date GMT: 2016-02-10 11:36:36

Export of Post and Page has been powered by [ Universal Post Manager ] plugin from www.ProfProjects.com