最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

wp mail - Could not get attachment using wp_mail

programmeradmin1浏览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

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

Share Improve this question edited May 23, 2016 at 8:50 Riffaz Starr asked May 23, 2016 at 7:22 Riffaz StarrRiffaz Starr 7964 gold badges20 silver badges41 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 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");
发布评论

评论列表(0)

  1. 暂无评论