2017-08-28 47 views
0

我有一個帶有文件上傳字段的聯繫人表單(CV上傳)。WordPress發送帶有上傳附件的郵件

但是我可以通過郵件和郵件發送沒有問題,但我從網上使用的示例附上表格中的簡歷不起作用。

有什麼我在這裏失蹤?

<input type="text" name="fullName" placeholder="Full Name: (required)" required> 
<input type="email" name="email" placeholder="Email: (required)" required> 
<input type="tel" name="tel" placeholder="Telephone: (required)" required> 
<textarea name="message" placeholder="Quick message"></textarea> 
<span>Please upload a copy of your cv</span><span><input type="file" name="cv" required></span> 


//Handle the file upload and attachment 
if (! function_exists('wp_handle_upload')) { 
    require_once(ABSPATH . 'wp-admin/includes/file.php'); 
} 
$uploadedfile = $_FILES['cv']; 
$upload_overrides = array('test_form' => false); 
$movefile = wp_handle_upload($uploadedfile, $upload_overrides); 
if ($movefile && ! isset($movefile['error'])) { 
    $movefile['url']; 
} 
$attachments = array($movefile['file']); 

$mailoffice = wp_mail('[email protected]', 'New Candidate Application', $messageOffice, $headers, $attachments); 
+0

定義「不工作」 – Synchro

+0

郵件將從窗體中發送所有消息內容和發佈的值。但是,文件附件的PHP不包括附件。 –

+0

很確定'wp_mail'只需要一個文件名的數組......'wp_handle_upload'返回的是不同的東西。 – CBroe

回答

0

好的,所以我通過長途跋涉得到了這個工作。

首先我將文件上傳到網站,作爲輸出表單頁面的附件。

然後,我使用以下獲取附件路徑,將其添加爲wp_mail()中的附件,然後在發送郵件後最後刪除附件。

//Handle the CV Upload 
require_once(ABSPATH . 'wp-admin/includes/image.php'); 
require_once(ABSPATH . 'wp-admin/includes/file.php'); 
require_once(ABSPATH . 'wp-admin/includes/media.php');   

$attachment_id = media_handle_upload('cv', $_POST['post_id']); 
$attachments = get_attached_file($attachment_id); 

$mailoffice = wp_mail('[email protected]', 'New Candidate Application', $messageOffice, $headers, array($attachments)); 
wp_delete_attachment($attachment_id, true); 

它的質樸,但它的作品。