我有一个带有文件上传字段的联系表单(CV上传)。
我可以得到邮件和邮件没有问题但是,我从网上用来附加表格中的简单的例子都没有用。
我在这里缺少什么?
<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('james1@knoppysdev.com', 'New Candidate Application', $messageOffice, $headers, $attachments );
答案 0 :(得分: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('james1@knoppysdev.com', 'New Candidate Application', $messageOffice, $headers, array($attachments) );
wp_delete_attachment( $attachment_id, true );
它的质朴但它的作品。