新しい投稿と電子メールを作成する簡単なフロントエンドのWordPressフォーム(複数の添付ファイルあり)を作成しました。添付ファイルが配信されないことを除いて、すべてが期待どおりに動作しています。私のwp_mail添付ファイルが電子メールで送信されていません
あなたは以下のコードを見てください。$ attachmentsにファイルのパスを配列として挿入しようとしていますが、何も送信されません。私は何が間違っているのか分かりません。
//SEND THE EMAIL
function set_html_content_type() {
return 'text/html';
}
$inv_query_email = '[email protected]';
$admin_email = '[email protected]';
$to = array(
$inv_query_email,
//$admin_email
);
$page_slug = get_permalink($pid);
$subject = 'BSP: Invoice Query | '.$refno.'';
ob_start();
include plugin_dir_path(__FILE__).'/email_templates/bsp_inv_query_template.php';
$bsp_inv_query_message = ob_get_contents();
ob_end_clean();
$headers[] = 'From: '.$username.' <'.$useremail.'>';
//GET ATTACHMENTS
if (! function_exists('wp_handle_upload')) {
require_once(ABSPATH . 'wp-admin/includes/file.php');
}
$attachments = array();
$files = $_FILES['bsp_inv_query_upload'];
foreach ($files['name'] as $key => $value) {
if ($files['name'][$key]) {
$file = array(
'name' => $files['name'][$key],
'type' => $files['type'][$key],
'tmp_name' => $files['tmp_name'][$key],
'error' => $files['error'][$key],
'size' => $files['size'][$key]
);
//UPLOAD AND ATTACH TO POST - WORKS AS EXPECTED
$_FILES = array("bsp_inv_query_upload" => $file);
foreach ($_FILES as $file => $array) {
$newupload = insert_attachment($file,$pid);
}
//CREATE EMAIL ATTACHMENT
$emailfile = wp_handle_upload($file);
//$attachments[] = $emailfile['file']; //ALSO TRIED THIS
array_push($attachments, $emailfile['file']);
}
}
add_filter('wp_mail_content_type', 'set_html_content_type');
wp_mail($to, $subject, $bsp_inv_query_message, $headers, $attachments);
remove_filter('wp_mail_content_type', 'set_html_content_type');
HTMLフォーム::私はあなたが次のPHPコードのような添付ファイルを作成してください示唆この場合
<!-- BSP INVOICE QUERY FORM -->
<form id="bsp_inv_query" class="bsp_inv_query" name="bsp_inv_query" method="post" action="<?php the_permalink(); ?>" enctype="multipart/form-data">
<ul class="bsp_form">
<li><div class="required_txt">* Required</div><input placeholder="Name" type="text" class="log_title active" id="bsp_inv_query_name" name="bsp_inv_query_name" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Branch" type="text" class="log_title active" id="bsp_inv_query_branch" name="bsp_inv_query_branch" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Telephone" type="text" class="log_title active" id="bsp_inv_query_tel" name="bsp_inv_query_tel" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Email" type="text" class="log_title active" id="bsp_inv_query_email" name="bsp_inv_query_email" /></li>
<li><div class="required_txt">* Required</div><input placeholder="PAX Name/Surname" type="text" class="log_title active" id="bsp_inv_query_pax" name="bsp_inv_query_pax" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Ticket Number" type="text" class="log_title active" id="bsp_inv_query_ticket" name="bsp_inv_query_ticket" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Airline Code" type="text" class="log_title active" id="bsp_inv_query_airline" name="bsp_inv_query_airline" /></li>
<li><div class="required_txt">* Required</div><input placeholder="Invoice Number" type="text" class="log_title active" id="bsp_inv_query_inv_no" name="bsp_inv_query_inv_no" /></li>
</ul>
<div class="required_txt">* Required</div>
<textarea placeholder="Description of query..." class="log_message" id="bsp_inv_query_desc" name="bsp_inv_query_desc" /></textarea>
<div class="log_upload_holder">
<input type="file" data-multiple-caption="{count} files selected" multiple name="bsp_inv_query_upload[]" id="bsp_inv_query_upload" class="upload_attachment"><label for="bsp_inv_query_upload" id=""><svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px"
width="200px" height="200px" viewBox="0 0 200 200" style="enable-background:new 0 0 200 200;" xml:space="preserve"><path class="st0" d="M100.1,2.5c2.9,0,5.7,1.1,7.9,3.3l44.8,44.8c2.1,2.1,3.3,4.9,3.3,7.9s-1.2,5.8-3.3,7.9c-2.1,2.1-4.9,3.3-7.9,3.3s-5.8-1.2-7.9-3.3l-25.8-25.8v104.7c0,6.2-5,11.2-11.2,11.2c-6.1,0-11.1-5-11.1-11.2V40.5L63,66.3c-1.9,2-4.7,3.2-7.7,3.3c-3,0-5.9-1.2-8-3.3c-2.1-2.1-3.3-4.9-3.3-7.9s1.2-5.8,3.3-7.9L92,5.7C94.4,3.6,97.2,2.5,100.1,2.5zM54.5,57.8L54.5,57.8C54.5,57.7,54.5,57.7,54.5,57.8z"/><path class="st0" d="M188.9,128.6c-6.2,0-11.2,5-11.2,11.1v38.1h-48.4H70.7H22.2v-38.1c0-6.1-5-11.1-11.2-11.1c-6.1,0-11.1,5-11.1,11.1v49.2c0,6.3,4.9,11.2,11.1,11.2h60.3h57.3h60.3c6.2,0,11.1-4.9,11.1-11.2v-49.2C200,133.5,195,128.6,188.9,128.6z"/></svg><br><span>Upload a file…</span></label>
<div class="remove_files"></div>
</div>
<div class="clearfix"></div>
<!-- HIDDEN INPUTS SET BY SELECTS -->
<input type="hidden" name="bsp_inv_query_department" id="bsp_inv_query_department" value="26" />
<input type="hidden" name="bsp_inv_query_category" id="bsp_inv_query_category" value="27" />
<input type="hidden" name="bsp_inv_query_topic" id="bsp_inv_query_topic" value="43" />
<!-- NONCE -->
<input type="hidden" name="bsp_inv_query" id="bsp_inv_query" value="bsp_inv_query" />
<?php wp_nonce_field('bsp_inv_query'); ?>
<input type="submit" class="button-primary" id="submit" name="submit" tabindex="6" value="Submit Query" />
</form>
は、あなたのHTMLフォームは、私が質問にそれを追加した –
@MajidAbbasiを追加します。ありがとう。 – DakotaDC3