What I am trying to achieve is to upload and send some files via form here's my form:<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" />
and here's my 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);
after dumping $attachments show empty array and
$uploadfile shows path till uploads/ NO FILENAME HERE
tried to search around the internet but found only answers how to attach a file that is already on the server any help would be appreciated, thanks in advance
UPDATE
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() . "
");
return false;
}
this expeption looks as follows:
exception 'phpmailerException' with message 'Could not access file: ' in /home/ad000min999/public_html/ogo/wp-includes/class-phpmailer.php:1971 Stack trace: #0 /home/ad000min999/public_html/ogo/wp-includes/pluggable.php(487): PHPMailer->addAttachment('') #1 /home/ad000min999/public_html/ogo/wp-content/themes/flatads/single.php(244): wp_mail('yucikkravets@gm...', 'asdas', 'Name: asdasd ??...', 'From