@tari72
php copy should support remote files, so just change the path to your master file:
$master_copy='https://www.mysite.it/subfolder/private/my_remote_file.pdf';
IF IT DOESN’T WORK
here you can find a good tutorial with 4 solutions to read a remote file and grab its content.
Once you have putted the content of the remote file in to a variable ($content in the tutorial), just write it to a file with a line of code like this:
file_put_contents($file, $content);
Suppose you decide to use the second method described in the tutorial (remember to verify that your hosting service has allow_url_fopen setted to true in php.ini), you can integrate it in my code like this:
add_action( 'wpcf7_before_send_mail', 'create_unique_coupon_and_send_it' );
function create_unique_coupon_and_send_it( $cf7 ) {
//check if this is the right form
if ($cf7->id==741){
$uploads = wp_upload_dir();
//define some constants
define ('MY_FILE_PATH',$uploads['path'].'/myfile/');
//set filenames
$master_copy='https://www.mysite.it/subfolder/private/my_remote_file.pdf';
$copy_to_send=MY-FILE_PATH.'attachment.pdf';
if ($cf7->mail['use_html']==true)
$nl="<br/>";
else
$nl="\n";
// get the remote file
$content = file_get_contents('$master_copy');
if ($content !== false) {
//make a copy of the master file and attach it
if ( file_put_contents($copy_to_send, $content) !== false ){
//Let'go to the file attachment!
$cf7->uploaded_files = array ( 'coupon' => $copy_to_send );
}
}
//Let'go to the file attachment!
$cf7->uploaded_files = array ( 'coupon' => $copy_to_send );
//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;
}
}