<legend id='x73dr'><style id='x73dr'><dir id='x73dr'><q id='x73dr'></q></dir></style></legend>

      <small id='x73dr'></small><noframes id='x73dr'>

      <i id='x73dr'><tr id='x73dr'><dt id='x73dr'><q id='x73dr'><span id='x73dr'><b id='x73dr'><form id='x73dr'><ins id='x73dr'></ins><ul id='x73dr'></ul><sub id='x73dr'></sub></form><legend id='x73dr'></legend><bdo id='x73dr'><pre id='x73dr'><center id='x73dr'></center></pre></bdo></b><th id='x73dr'></th></span></q></dt></tr></i><div id='x73dr'><tfoot id='x73dr'></tfoot><dl id='x73dr'><fieldset id='x73dr'></fieldset></dl></div>

      • <bdo id='x73dr'></bdo><ul id='x73dr'></ul>

        <tfoot id='x73dr'></tfoot>

        使用 phpMailer 和 PHP 从表单发送文件附件

        时间:2023-05-20

        1. <legend id='ppdHp'><style id='ppdHp'><dir id='ppdHp'><q id='ppdHp'></q></dir></style></legend>

          <small id='ppdHp'></small><noframes id='ppdHp'>

            <bdo id='ppdHp'></bdo><ul id='ppdHp'></ul>
          • <tfoot id='ppdHp'></tfoot>
            <i id='ppdHp'><tr id='ppdHp'><dt id='ppdHp'><q id='ppdHp'><span id='ppdHp'><b id='ppdHp'><form id='ppdHp'><ins id='ppdHp'></ins><ul id='ppdHp'></ul><sub id='ppdHp'></sub></form><legend id='ppdHp'></legend><bdo id='ppdHp'><pre id='ppdHp'><center id='ppdHp'></center></pre></bdo></b><th id='ppdHp'></th></span></q></dt></tr></i><div id='ppdHp'><tfoot id='ppdHp'></tfoot><dl id='ppdHp'><fieldset id='ppdHp'></fieldset></dl></div>

                <tbody id='ppdHp'></tbody>
                  本文介绍了使用 phpMailer 和 PHP 从表单发送文件附件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  限时送ChatGPT账号..

                  我在 example.com/contact-us.php 上有一个表单,看起来像这样(简化):

                  I have a form on example.com/contact-us.php that looks like this (simplified):

                  <form method="post" action="process.php" enctype="multipart/form-data">
                    <input type="file" name="uploaded_file" id="uploaded_file" />
                    <input type="hidden" name="MAX_FILE_SIZE" value="10000000" />
                  </form>
                  

                  在我的 process.php 文件中,我有以下代码利用 PHPMailer() 发送电子邮件:

                  In my process.php file, I have the following code utilizing PHPMailer() to send an email:

                  require("phpmailer.php");
                  
                  $mail = new PHPMailer();
                  
                  $mail->From     = me@example.com;
                  $mail->FromName = My name;
                  $mail->AddAddress(me@example.com,"John Doe");
                  
                  $mail->WordWrap = 50;
                  $mail->IsHTML(true);
                  
                  $mail->Subject  =  "Contact Form Submitted";
                  $mail->Body     =  "This is the body of the message.";
                  

                  电子邮件正确发送正文,但没有uploaded_file的附件.

                  The email sends the body correctly, but without the Attachment of uploaded_file.

                  我的问题

                  我需要将表单中的文件 uploaded_file 附加到电子邮件中并发送.在 process.php 脚本通过电子邮件发送文件后,我不关心保存文件.

                  I need the file uploaded_file from the form to be attached to the email, and sent. I do NOT care about saving the file after the process.php script sends it in an email.

                  我知道我需要在某处(我假设在 Body 行下)添加 AddAttachment(); 以发送附件.但是...

                  I understand that I need to add AddAttachment(); somewhere (I'm assuming under the Body line) for the attachment to be sent. But...

                  1. 我在 process.php 文件的顶部放了什么来拉入文件 uploaded_file?喜欢使用 $_FILES['uploaded_file'] 从 contact-us.php 页面中提取文件吗?
                  2. AddAttachment(); 的内容是什么来附加文件并与电子邮件一起发送?此代码需要放在何处?
                  1. What do I put at the top of the process.php file to pull in the file uploaded_file? Like something using $_FILES['uploaded_file'] to pull in the file from the contact-us.php page?
                  2. What goes inside of AddAttachment(); for the file to be attached and sent along with the email and where does this code need to go?

                  请帮忙并提供代码!谢谢!

                  Please help and provide code!Thanks!

                  推荐答案

                  尝试:

                  if (isset($_FILES['uploaded_file']) &&
                      $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
                      $mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
                                           $_FILES['uploaded_file']['name']);
                  }
                  

                  也可以在此处找到基本示例.

                  Basic example can also be found here.

                  AddAttachment 的函数定义是:

                  public function AddAttachment($path,
                                                $name = '',
                                                $encoding = 'base64',
                                                $type = 'application/octet-stream')
                  

                  这篇关于使用 phpMailer 和 PHP 从表单发送文件附件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:以编程方式将可下载文件添加到 Woocommerce 产品 下一篇:如何在PHP中检查上传的文件类型

                  相关文章

                  最新文章

                1. <tfoot id='WeHVX'></tfoot>

                    <i id='WeHVX'><tr id='WeHVX'><dt id='WeHVX'><q id='WeHVX'><span id='WeHVX'><b id='WeHVX'><form id='WeHVX'><ins id='WeHVX'></ins><ul id='WeHVX'></ul><sub id='WeHVX'></sub></form><legend id='WeHVX'></legend><bdo id='WeHVX'><pre id='WeHVX'><center id='WeHVX'></center></pre></bdo></b><th id='WeHVX'></th></span></q></dt></tr></i><div id='WeHVX'><tfoot id='WeHVX'></tfoot><dl id='WeHVX'><fieldset id='WeHVX'></fieldset></dl></div>
                  1. <legend id='WeHVX'><style id='WeHVX'><dir id='WeHVX'><q id='WeHVX'></q></dir></style></legend>

                        <bdo id='WeHVX'></bdo><ul id='WeHVX'></ul>
                    1. <small id='WeHVX'></small><noframes id='WeHVX'>