title: PHPMailer, SMTP and problems with gmail
body: <p>So I made a timesheet form and need to send it via SMTP. I need the form to take form entries and send them to a main email(office Manager) and the person who filled out their timesheet(the employee). I got it working with the mail() function but they needed file attachment,so I went the PHPMailer route. The problem is the employee gets a spam message(screenshot below) when you enter an email from a service like yahoo, gmail or other third parties. I get the email when I test it with my personal website email but not when I use my gmail email address. If this is a security option with gmail and other third party email services that would really suck, because I cant tell every employee how to change their email settings. But I don't think it is, I think I'm doing something wrong. I have attached the php code.</p>
  
  <p>Thanks Let me know if you have any questions.</p>
  
  <pre><code>&lt;?php
  $msg = "";
  use PHPMailer\PHPMailer\PHPMailer;
  include_once "PHPMailer/PHPMailer.php";
  include_once "PHPMailer/Exception.php";
  include_once "PHPMailer/SMTP.php";
  
  if (isset($_POST['submit'])) {
  
  //varibles from form
  $email = $_POST['email'];
  $name = $_POST['employee'];
  $date = $_POST['date'];
  $jobnum = $_POST['job#'];
  $radio = $_POST['radiobtn'];
  $customer = $_POST['customer'];
  $address = $_POST['location'];
  $jobdes = $_POST['jobdescription'];
  $starttime = strtotime($_POST['starttime']);
  $lunchtime = $_POST['lunch'];
  $stoptime = strtotime($_POST['stoptime']);
  $totalhours = $_POST['totalhours'];
  $drivetime = $_POST['drivetime'];
  $notes = $_POST['notes'];
  $m1 = $_POST['m-1'];
  $m2 = $_POST['m-2'];
  $m3 = $_POST['m-3'];
  $m4 = $_POST['m-4'];
  $m5 = $_POST['m-5'];
  $m6 = $_POST['m-6'];
  $m7 = $_POST['m-7'];
  
  $q1 = $_POST['q-1'];
  $q2 = $_POST['q-2'];
  $q3 = $_POST['q-3'];
  $q4 = $_POST['q-4'];
  $q5 = $_POST['q-5'];
  $q6 = $_POST['q-6'];
  $q7 = $_POST['q-7'];
  
  $e1 = $_POST['e-1'];
  $e2 = $_POST['e-2'];
  $e3 = $_POST['e-3'];
  $e4 = $_POST['e-4'];
  $e5 = $_POST['e-5'];
  $e6 = $_POST['e-6'];
  $e7 = $_POST['e-7'];
  
  $t1 = $_POST['t-1'];
  $t2 = $_POST['t-2'];
  $t3 = $_POST['t-3'];
  $t4 = $_POST['t-4'];
  $t5 = $_POST['t-5'];
  $t6 = $_POST['t-6'];
  $t7 = $_POST['t-7'];
  
  //HTML EMAIL TABLE WITH FORM DATA ENTRIES
  $message = "&lt;html&gt;&lt;body&gt;";
  $message .= '&lt;table rules="all" style="border-color: #666;" cellpadding="10"&gt;';
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Tech Name:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" .$name. "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Job #:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" .$jobnum. "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Date:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $date . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Start Time:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . date('h:i a', $starttime) . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Lunch Duration:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $lunchtime . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Stop Time:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . date('h:i a', $stoptime) . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Total Hours:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $totalhours . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Drive Time:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $drivetime . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Job Complete:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $radio . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Customer:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $customer . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Location/Address:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $address . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Job Description:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $jobdes . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Notes:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $notes . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;FILE:&lt;/strong&gt; &lt;/td&gt;&lt;td&gt;" . $file . "&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;&lt;strong&gt;Materials:&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Qty:&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Each:&lt;/strong&gt;&lt;/td&gt; &lt;td&gt;&lt;strong&gt;Total:&lt;/strong&gt;&lt;/td&gt;&lt;/tr&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m1&lt;/td&gt;&lt;td&gt;$q1&lt;/td&gt;&lt;td&gt;$e1&lt;/td&gt;&lt;td&gt;$t1&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m2&lt;/td&gt;&lt;td&gt;$q2&lt;/td&gt;&lt;td&gt;$e2&lt;/td&gt;&lt;td&gt;$t2&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m3&lt;/td&gt;&lt;td&gt;$q3&lt;/td&gt;&lt;td&gt;$e3&lt;/td&gt;&lt;td&gt;$t3&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m4&lt;/td&gt;&lt;td&gt;$q4&lt;/td&gt;&lt;td&gt;$e4&lt;/td&gt;&lt;td&gt;$t4&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m5&lt;/td&gt;&lt;td&gt;$q5&lt;/td&gt;&lt;td&gt;$e5&lt;/td&gt;&lt;td&gt;$t5&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m6&lt;/td&gt;&lt;td&gt;$q6&lt;/td&gt;&lt;td&gt;$e6&lt;/td&gt;&lt;td&gt;$t6&lt;/td&gt;";
  $message .= "&lt;tr&gt;&lt;td&gt;$m7&lt;/td&gt;&lt;td&gt;$q7&lt;/td&gt;&lt;td&gt;$e7&lt;/td&gt;&lt;td&gt;$t7&lt;/td&gt;";
  $message .= "&lt;/table&gt;";
  $message .= "&lt;/body&gt;&lt;/html&gt;";
  
  //SOMETHING TO DO WITH SENDING A ATTACHMENT???
      if (isset($_FILES['attachment']['name']) &amp;&amp; $_FILES['attachment']['name'] != "") {
          $file = "attachment/" . basename($_FILES['attachment']['name']);
          move_uploaded_file($_FILES['attachment']['tmp_name'], $file);
      } else
          $file = "";
  
      $mail = new PHPMailer();
  
  //set a host
  $mail-&gt;Host = "mail.gradyelectricforms.com";
  
  //enable SMTP
  $mail-&gt;isSMTP();
  
  //set authentication to true
  $mail-&gt;SMTPAuth = true;
  
  //set login details for gmail account
  $mail-&gt;Username = "forms@gradyelectricforms.com";
  $mail-&gt;Password = "mypassword";
  
  //set type of protection
  $mail-&gt;SMTPSecure = "ssl"; // or we can use TLS
  
  //set a port
  $mail-&gt;Port = 465; //or 587 if TLS
  
  $mail-&gt;setFrom($email);
  $mail-&gt;Subject = "NEW TIMESHEET";
  $mail-&gt;addAddress('example@123.com');
  $mail-&gt;addAddress($email);
  $mail-&gt;isHTML(true);
  $mail-&gt;Body = $message;
  $mail-&gt;addAttachment($file);
  
      if ($mail-&gt;send())
          $msg = "Your form has been sent, thank you!";
      else
          $msg = "Please try again!";
  
      unlink($file);
  }
  ?&gt;
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/CbEHt.png" rel="nofollow noreferrer">Gmail Error Message found in spam</a></p>