使用PHP mailer版本6.1发送带有附件的电子邮件

时间:2020-05-14 15:28:00

标签: php phpmailer

请帮助我,我通过mylaptop上的composer安装了PHPMailer,并将同一文件夹上传到远程服务器。我按如下所示设置表单参数和php代码,但我不知道为什么表单未提交? 它将清除表单,即使我设置了错误消息,它也不会放入电子邮件中,甚至不会显示任何错误。

是我需要与托管公司联系还是在下面的脚本中犯了一个错误?

<?php
// Import PHPMailer classes into the global namespace
// These must be at the top of your script, not inside a function
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;

// initialize the $message variable
$message='';
if (isset($_POST['submit'])) {
  $issues='';
  foreach($_POST["issues"] as $row)
  {
    $issues .= $row . ', ';
  }
  $issues = substr($issues, 0, -2);

  $path = 'upload/' . $_FILES["photo"]["name"];
  move_uploaded_file( $_FILES["photo"]["tmp_name"], $path);

  $message = '
  <h3 align="center">Customer Details</h3>
    <table border="1" width="100%" cellpadding="5" cellspacing="5">
      <tr>
        <td width="30%">Name</td>
        <td width="70%">'.$_POST["name"].'</td>
      </tr>
     <tr>
        <td width="30%">Email</td>
        <td width="70%">'.$_POST["email"].'</td>
      </tr>
      <tr>
        <td width="30%">Phone</td>
        <td width="70%">'.$_POST["phone"].'</td>
      </tr>
      <tr>
        <td width="30%">Your Usual Top Size (UK)</td>
        <td width="70%">'.$_POST["topsize"].'</td>
      </tr>
      <tr>
        <td width="30%">Size of Your Best-Fitting Bra</td>
        <td width="70%">'.$_POST["bestfitting"].'</td>
      </tr>

      <tr>
        <td width="30%">Underbust (inches)</td>
        <td width="70%">'.$_POST["underbust"].'</td>
      </tr>
      <tr>
        <td width="30%">Bust (inches)</td>
        <td width="70%">'.$_POST["bust"].'</td>
      </tr>

      <tr>
        <td width="30%">Country</td>
        <td width="70%">'.$_POST["country"].'</td>
      </tr>
      <tr>
        <td width="30%">Issuees with your current bra size</td>
        <td width="70%">'.$issues.'</td>
      </tr>
    </table>
  ';
    // Load Composer's autoloader
    require 'vendor/autoload.php';
    // Instantiation and passing `true` enables exceptions like this  $mail = new PHPMailer(true);
    $mail = new PHPMailer;
    $mail->isSMTP();                                            
    $mail->Host       = 'us12.tmd.cloud';                   
    $mail->SMTPAuth   = true;                                   
    $mail->Username   = 'admin@dunniessentials.com';                    
    $mail->Password   = 'secretpassword';                              
    $mail->SMTPSecure = 'SSL';         
    $mail->Port       = 465;                                    // TCP port to connect to, use 465 for `PHPMailer::ENCRYPTION_SMTPS` above

    //Recipients
    $mail->From = $_POST["email"];
    $mail->FromName = $_POST["name"];
    $mail->addAddress('admin@duuniessentials.com', 'Admin');     // Add a recipient

    // content
    $mail->WordWrap = 50;

    $mail->isHTML(true); 

    $mail->addAttachment($path);         // Add attachments

    $mail->Subject = 'BRA EXPERT, PREDICT MY SIZE';
    $mail->Body    = $message;

    IF($mail->send()) 
    {
      $message = '<div class="alert alert-success"> Request Successfully Submitted</div>';
      unlink($path);
    }
    else 
    {
      $message = '<div class="alert alert-danger"> There is an Error!</div>';
    }
}
?>
<!DOCTYPE html>
<html>
    <head>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1" />
        <title> Bra Expert Predict My Size | Bras in Nigeria, Uk cups AA-KK, Bras Fit Expert, World's Best Bra</title>

        <meta name="keywords" content="Dunni Essentials, Bras, Shapewear. Bras in Nigeria, Uk cups AA-KK,
            Bras Fit Expert, World's Best Bra,  Bra Fitting service" />
        <meta name="Description" content="Dunni Essentials" />
        <meta name="viewport" content="width=device-width, initial-scale=1">

          <!-- Header -->
       <?php
       include('./includes/header.php'); 
       ?>
  <!-- // Header ends-->

         <main role="main" id="main">
            <div class="container">

                <!-- upper content -->
                <section id="brafittinguppercontent">
                <div class="row">
                    <h2 class="text-center text-danger">BRA EXPERT, PREDICT MY SIZE</h2>
                    <br/>


                    <?php echo $message; ?>

                    <div class="col-sm-6 text-justify">
                    <p>Can't get into the store? Our bra Expert service can help you find your size online. </p>
                      <p>
                        Simply send in a picture of yourself in a fitted t-shirt, wearing your best-fitting unpadded bra,
                         tell us your dress size and the size of your best-fitting bra – and we’ll predict the perfect bra size for you! </p>
                         <p>
                        Submit your details below and we’ll get back to you in a flash by WhatsApp.</p>
                    </div>

                    <div class="col-sm-offset-2 col-sm-4">
                        <!-- image -->
                           <img src="images/braexpert.jpg" class="img-responsive">
                       </div>
                </div>
                </section>

                <section id="braservice">

                   <div class="row">
                      <h3 class="text-center text-danger">LET US PREDICT YOUR BRA SIZE</h3>
                      <br/>
                     <div class="col-md-8"  style="margin:0 auto; float:none;">

                      <form method="post" enctype="multipart/form-data">
                        <div class="row">

                          <div class="col-md-6">
                              <div class="form-group">
                                <label>Enter Name</label>
                                <input type="text" name="name" placeholder="Enter  Name"
                                    class="form-control" required />
                              </div>
                              <div class="form-group">
                                <label>Your Email</label>
                                <input type="email" name="email" placeholder="Enter Email"
                                    class="form-control" required />
                              </div>
                              <div class="form-group">
                                <label>Phone</label>
                                <input type="text" name="phone" placeholder="Enter Your phone number"
                                    class="form-control" required pattern="\d*" />
                              </div>
                              <div class="form-group">
                                <label>Your Usual Top Size (UK)</label>
                                <input type="text" name="topsize" placeholder="Your Usual Top Size (UK)"
                                    class="form-control"  />
                              </div>
                              <div class="form-group">
                                <label>Size of Your Best-Fitting Bra</label>
                                <input type="text" name="bestfitting" placeholder="Enter Size of Your Best-Fitting Bra"
                                    class="form-control" required  />
                              </div>
                              <div class="form-group">
                                <label>Measurements: Underbust (inches)</label>
                                <input type="text" name="underbust" placeholder="Enter Your Measurements: Underbust (inches)"
                                    class="form-control" />
                              </div>
                          </div>
                          <div class="col-md-6">
                              <div class="form-group">
                                <label>Bust (inches)</label>
                                <input type="text" name="bust" placeholder="Enter Your Bust (inches)"
                                    class="form-control" />
                              </div>
                              <div class="form-group">
                                <label>Upload Your Photo</label>
                                <input type="file" name="photo" accept=".jpg, .jpeg, .png, .gif, .pdf" />
                              </div>
                              <div class="form-group">
                                <label>Country</label>
                                <input type="text" name="country" placeholder="Enter Your Country"
                                    class="form-control" />
                              </div>
                              <div class="form-group">
                                <label>Select Issues with your current bra size</label>
                                <select name="issues[]" class="form-control" multiple required style="height:150px;">
                                <option value="Spill from above cups">Spill from above cups</option>
                                <option value="Spill from under arms">Spill from under arms</option>
                                <option value="Loose band">Loose band</option>
                                <option value="Tight band">Tight band</option>
                                <option value="Spill from under band">Spill from under band</option>
                                </select>
                              </div>
                          </div>

                       </div>
                       <div class="form-group" align="center">
                          <button class="btn btn-danger btn-lg" name="send" type="submit">Submit</button>
                       </div>

                      </form>
                    </div>
                  </div>

                </section>  

            </div>


        </main>

            <!-- FOOTER -->

       <?php
       include('./includes/footer.php'); 
       ?>

       <!-- End FOOTER  -->
    </body>
</html>

0 个答案:

没有答案