我想要实现的是通过表单上传和发送一些文件
这是我的形式:
<form enctype="multipart/form-data" name="contactForm" action="<?php the_permalink(); ?>" id="contact-form" method="post" class="contactform" >
<input type="file" name="file" class="attachment" />
这是我的PHP:
$attachments = array();
if (isset($attachments))
{
$uploadfile = WP_CONTENT_DIR ."/uploads/".$attachments['file']['name'];
move_uploaded_file($attachments['file']['tmp_name'], $uploadfile);
var_dump($attachments);
}
wp_mail($emailTo, $subject, $body, $headers, $attachments);
倾销后
$ attachments显示空数组和
$ uploadfile显示路径直到上传/没有文件在这里
试图在互联网上搜索,但只发现如何附加已在服务器上的文件的答案
任何帮助将不胜感激,提前谢谢
更新
if (isset($_FILES['file']))
{
$attachments = $_FILES['file'];
$uploadfile = WP_CONTENT_DIR ."/uploads/".$attachments['file']['name'];
move_uploaded_file($attachments['tmp_name'], $uploadfile);
var_dump($_FILES);
}
wp_mail($emailTo, $subject, $body, $headers, $attachments);
UPD2
catch (phpmailerException $e) {
$this->setError($e->getMessage());
if ($this->exceptions) {
throw $e;
}
$this->edebug($e->getMessage() . "\n");
return false;
}
这个例子如下:
/home/ad000min999/public_html/ogo/wp-includes/class-phpmailer.php:1971错误'phpmailerException',消息'无法访问文件:'堆栈跟踪:#0 / home / ad000min999 / public_html / ogo / wp- includes / pluggable.php(487):PHPMailer-&gt; addAttachment('')#1 /home/ad000min999/public_html/ogo/wp-content/themes/flatads/single.php(244):wp_mail('yucikkravets @ gm ......','asdas','姓名:asdasd ?? ......','来自