第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

PHPMailer 多個附件發(fā)送電子郵件,但沒有文件

PHPMailer 多個附件發(fā)送電子郵件,但沒有文件

PHP
慕勒3428872 2022-08-19 10:12:55
我似乎已經(jīng)嘗試了在這個特定主題上找到的每一個StackOverflow(而且有很多),但大多數(shù)人都忘記了在表單標(biāo)簽或其他東西上。我仍然收到電子郵件,只是沒有附加任何文件。enctype當(dāng)我提交表單時,我的數(shù)組似乎沒有被填滿。下面的代碼發(fā)送html電子郵件,其中包含提交的字段數(shù)據(jù),但沒有附件。$_FILES這是表單提交輸入數(shù)據(jù)但沒有附件時日志中的最新錯誤:[24-Jan-2020 22:06:33 UTC] PHP Warning:  count(): Parameter must be an array or an object that implements Countable in *******/public_html/rtform/contact.php on line 89我已經(jīng)在下面的代碼中指出了第89行。這是我的表單的開頭和結(jié)尾,我的文件輸入在底部(表單的其余部分太長,無法在此處包含整個內(nèi)容:<form id="contact-form" method="POST" action="contact.php" role="form" enctype="multipart/form-data">    <div class="controls">        <!-- the middle of the form here -->        <div class="row">            <h3 class="form_title">Upload Additional Supporting Documents</h3>            <div class="col-lg-12">                <label for="attachments[]">Select one or more files:                    <input name="attachments[]" type="file" multiple="multiple">                </label>            </div>        </div>        <hr/>        <div class="form-group">            <div class="g-recaptcha" data-sitekey="**************************************" data-callback="verifyRecaptchaCallback" data-expired-callback="expiredRecaptchaCallback"></div>            <input class="form-control d-none" data-recaptcha="true" required data-error="Please complete the Captcha">            <div class="help-block with-errors"></div>        </div>        <p><span class="red">Fields marked with * denotes a required field.</span></p>        <input type="submit" class="btn btn-success btn-send" value="Submit Order">        <div class="messages"></div>    </div><!-- end .controls --></form>
查看完整描述

1 回答

?
尚方寶劍之說

TA貢獻1788條經(jīng)驗 獲得超4個贊

值得問你的JS...


您正在執(zhí)行以下操作:


data: $(this).serialize(),

這將不包括文件附件。您需要使用 JS FormData 類并關(guān)閉一些 jQuery 功能。


首先,為文件輸入一個id,以便您可以更輕松地定位它(您的標(biāo)簽也應(yīng)該定位此id,而不是屬性):labelname


<input name="attachments[]" id="attachments" type="file" multiple="multiple">

然后更改 ajax 代碼以將表單數(shù)據(jù)放入對象中,然后將文件元素添加到其中:FormData


var fd = new FormData('contact-form');

var files = $("#attachments").get(0).files;


for (var i = 0; i < files.length; i++) {

  fd.append("attachments", files[i]);

}

$.ajax({

  type: "POST",

  url: url,

  data: fd,

  processData: false,

  contentType: false,

  success: function (data) {

    var messageAlert = 'alert-' + data.type;

    var messageText = data.message;


    var alertBox = '<div class="alert ' + messageAlert + ' alert-dismissable"><button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>' + messageText + '</div>';

    if (messageAlert && messageText) {

      $('#contact-form').find('.messages').html(alertBox);

      $('#contact-form')[0].reset();

      grecaptcha.reset();

    }

  },

  error: function (data) {

    //this is going to happen when you send something different from a 200 OK HTTP

    alert('Ooops, something happened: ' + data.message);

  }

});

注意:此方法在版本 10 之前的 Internet Explorer 中不起作用。


查看完整回答
反對 回復(fù) 2022-08-19
  • 1 回答
  • 0 關(guān)注
  • 121 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號