0

I am trying to create a form which can be sent by users with an attachment. The form works fine and sending the emails when it is submitted but without the attached file.

my form is :

<form method="post" class="flat-p-form p-form-flat-extra5color4" action="<?php the_permalink(); ?>" data-js-validate="true" data-js-highlight-state-msg="true" data-js-show-valid-msg="true">
    <div class="form-group">
        <label for="fotoattachment" class="p-label-required">Attachment <span style="color: red">(Attach Your Photos as A ZIP File.)</span></label>
        <div class="input-group p-has-icon">
            <input type="file" class="file form-control" id="fotoattachment" name="fotoattachment" required="required"/>
            <span class="input-group-state">
                <span class="p-position">
                    <span class="p-text">
                        <span class="p-required-text"><i class="fa fa-star"></i></span>
                    </span>
                </span>
            </span>
            <span class="p-field-cb"></span>
            <span class="input-group-icon"><i class="fa fa-paperclip"></i></span>
        </div>
    </div>
    <button class="btn" type="submit" name="confirm"><i class="fa fa-share-square-o"></i>&nbsp;Submit</button>
</form>

And my PHP is:

if(isset($_POST['confirm'])){
    $fullname = $_POST['sudentname'];
    $email = $_POST['email'];
    $comment = $_POST['comment'];
    $batch = $_POST['batch'];
    $mailbody = 'Name :'. $fullname . "\r\n".'Email: '.$email. "\r\n".'Comment: '.$comment. "\r\n".'Batch: '.$batch;


    /*  attachment */   
    move_uploaded_file($_FILES["fotoattachment"]["tmp_name"],WP_CONTENT_DIR .'/uploads/'.basename($_FILES['fotoattachment']['name']));
    $attachments = array(WP_CONTENT_DIR ."/uploads/".$_FILES["fotoattachment"]["name"]);

    $to = '[email protected]';
    $subject = 'Feedback from  Website';
    $headers = 'From: '.$fullname.' <'. $email. '>';

    wp_mail( $to, $subject, $mailbody, $headers, $attachments );
}

I am getting emails but not the attached files. Why is that?

[UPDATE]

When I check like this after form submitting :

foreach ($attachments as $key => $value) {
                echo "$key = $value\n";
            }

The out put is Array

1 Answer 1

1

Is the file correctly saved?

Did you try attaching a file via static path? Something like:

$attachments = array(WP_CONTENT_DIR ."/uploads/myfile.pdf");
1
  • I tried attaching static too. Also not working. It is not sending attachment even the path is static. May 24, 2016 at 5:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.