[英]I want to pass php variable in contact form 7 mail body
我想在聯系表單7郵件正文中傳遞php變量。 我已經在functions.php文件中添加了代碼。 我添加了隱藏字段,但是沒有用。 所以我想用其他方法檢查一下:
add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) {
//global $wpdb;
$wpcf7 = WPCF7_ContactForm :: get_current();
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$submited = array();
$submited['title'] = $wpcf7->title();
$submited['posted_data'] = $submission->get_posted_data();
$uploaded_files = $submission->uploaded_files();
}
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$position = $submited['posted_data']["file-181"];
$cf7_file_field_name = 'file-846';
$image_location = $uploaded_files[$cf7_file_field_name];
$mime_type = finfo_file($finfo, $image_location);
$token = GetRefreshedAccessToken('client_id', 'refresh_token', 'client_secret');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://www.googleapis.com/upload/drive/v3/files?uploadType=media',
CURLOPT_HTTPHEADER => array(
'Content-Type:' . $mime_type, // todo: runtime detection?
'Authorization: Bearer ' . $token
),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => file_get_contents($image_location),
CURLOPT_RETURNTRANSFER => 1
));
$response = curl_exec($ch);
$id = json_decode($response, TRUE);
$get_id = $id['id'];
$link= "https://drive.google.com/file/d/" . $get_id . "/view?usp=sharing";
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r($response);
}
}
如何在聯系表7郵件中發送$link
變量? 我想在郵件中添加此共享鏈接。
這可能使您走上正軌:
add_action('wpcf7_before_send_mail', 'save_application_form');
function save_application_form($wpcf7) {
//global $wpdb;
$wpcf7 = WPCF7_ContactForm :: get_current();
$submission = WPCF7_Submission::get_instance();
if ($submission) {
$submited = array();
$submited['title'] = $wpcf7->title();
$submited['posted_data'] = $submission->get_posted_data();
$uploaded_files = $submission->uploaded_files();
$finfo = finfo_open(FILEINFO_MIME_TYPE);
$position = $submited['posted_data']["file-181"];
$cf7_file_field_name = 'file-846';
$image_location = $uploaded_files[$cf7_file_field_name];
$mime_type = finfo_file($finfo, $image_location);
$token = GetRefreshedAccessToken('client_id', 'refresh_token', 'client_secret');
$ch = curl_init();
curl_setopt_array($ch, array(
CURLOPT_URL => 'https://www.googleapis.com/upload/drive/v3/files?uploadType=media',
CURLOPT_HTTPHEADER => array(
'Content-Type:' . $mime_type, // todo: runtime detection?
'Authorization: Bearer ' . $token
),
CURLOPT_POST => 1,
CURLOPT_POSTFIELDS => file_get_contents($image_location),
CURLOPT_RETURNTRANSFER => 1
));
$response = curl_exec($ch);
$id = json_decode($response, TRUE);
$get_id = $id['id'];
$link= "https://drive.google.com/file/d/" . $get_id . "/view?usp=sharing";
// Gets the Mail property
$mail = $submission->prop('mail');
// Append Google drive link to email body of Mail property
$mail['body'] .= $link;
// Set properties - with updated email body
$submission->set_properties(array('mail' => $mail));
$err = curl_error($ch);
curl_close($ch);
if ($err) {
echo "cURL Error #:" . $err;
} else {
print_r($response);
}
}
}
我添加了一些代碼來修改電子郵件正文-它只是附加了$link
變量。
我也將您所有的代碼移到了$submission
IF語句中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.