title: 2019 PHPMailer 6.07 / PHP Scrip How to send an email working example
body: <p>This code does not send an email with phpMailer v6.0.7 - I have tried various changes, tls, ssl, 465 and 587. I have found no errors in logs, php.ini with errors on, reporting error.  Worked with my hosting service to confirm connection settings.  I dont want to use composer but followed the document on github as well as pulled all files from github and uploaded to my cpanel.  Dont want to use 5.2 as its not supported anymore.  The live hosting services is using linux and PHP 7.  Check spam and all folders.  Cpanel has a trace mail or delivered mail to see if it was rejected and nothing stated that it was sent or rejected. Used Debug 2,3,4 with no errors.  Php.ini had the errors turned on. Seems like its nevered sent to the server to be rejected or allowed.          </p>
  
  <pre><code>    &lt;?php 
      use PHPMailer\PHPMailer\PHPMailer;
      use PHPMailer\PHPMailer\Exception;
      require 'PHPMailer/Exception.php';
      require 'PHPMailer/PHPMailer.php';
      require 'PHPMailer/SMTP.php';
  
  
      if(isset($_POST[‘submit’]))
  
      $mail = new PHPMailer(true);
  
      $mail-&gt;SMTPDebug = 2; // 0 = off (for production use) - 1 = client messages - 2 = client and server messages
      $mail-&gt;isSMTP(); 
  
      $mail-&gt;Host = 'mail.email.org'; 
      $mail-&gt;SMTPSecure = 'ssl'; &lt;-- Recommend by the hosting service &lt;--Hosting Service Docs verify this
      $mail-&gt;Port = 465; &lt;-- Recommend by the hosting service &lt;--Hosting Service Docs verify this
      $mail-&gt;SMTPAuth = true;
      $mail-&gt;Username = 'Mail@email.org';
      $mail-&gt;Password = 'Using the correct Password'; &lt;-- Resettled the password and verified its correct.
  
  
      $to = 'Mail@email.org'; &lt;-- sending this to myself
      $from = 'Mail@email.org'; &lt;--sending to myself
  
  &lt;Note this below was recommeended my hosting service to set it up this way below&gt;
      $first_name = ((isset($_POST['FirstName']))&amp;&amp;(!is_null($_POST['FirstName'])))? $_POST['FirstName']:'';
      $last_name = ((isset($_POST['LastName']))&amp;&amp;(!is_null($_POST['LastName'])))? $_POST['LastName']:'';
      $email = ((isset($_POST['Email']))&amp;&amp;(!is_null($_POST['Email'])))? $_POST['Email']:'';
      $age = ((isset($_POST['Age']))&amp;&amp;(!is_null($_POST['Age'])))? $_POST['Age']:'';
      $student = ((isset($_POST['Student']))&amp;&amp;(!is_null($_POST['Student'])))? $_POST['Student']:'';
      $agree18 = ((isset($_POST['Agree18']))&amp;&amp;(!is_null($_POST['Agree18'])))? $_POST['Agree18']:'';
  
  
     /* Set the mail sender. */
      $mail-&gt;setFrom( $to , 'Research');
  
     /* Add a recipient. */
      $mail-&gt;addAddress( $_POST['Email'] , 'Research');
     /* Set the subject. */
      $mail-&gt;Subject = 'Learn More about Research Requested';
  
      $mail-&gt;isHTML(TRUE);
      $mail-&gt;Body = '&lt;html&gt; "First Name:" . $first_name . " Last Name:" . $last_name .  " Email:". $email . " Age:" . $age . " Student:" . $student . " Agree18:" . $agree18 . ""
  &lt;/html&gt;';
  
  
      $mail-&gt;AltBody = ' "First Name:" . $first_name . " Last Name:" . $last_name .  " Email:". $email . " Age:" . $age . " Student:" . $student . " Agree18:" . $agree18 . ""
  '; &lt;-- Note I have tried /r/n and failed 
  
      if($mail-&gt;send()){
  
        $msg="Your email msg has been send";
  
  
      }else{
  
         $msg="mail msg has not been send"; 
         echo 'Mailer Error: ' . $mail-&gt;ErrorInfo;
       }
  
     ?&gt;
  
  
  
      &lt;!DOCTYPE html&gt;
      &lt;html lang="en"&gt;
      &lt;head&gt;
      &gt; 
      &lt;/head&gt;
      &lt;body&gt;
  
      &lt;div class="container"&gt;
  
      &lt;form  method="POST" enctype=multipart/form-data action=""&gt;  
      &lt;php echo '$msg' ?&gt;
      &lt;h4&gt;Want to Learn More? Please fill out the form below.&lt;/h4&gt;
       &lt;div class="form-group"&gt;
      &lt;label for="FirstName"&gt;First Name:&lt;/label&gt;
      &lt;input type="text" class="form-control" name="FirstName" id="FirstName" placeholder="First Name" required=""&gt;
    &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
      &lt;label for="LastName"&gt;Last Name:&lt;/label&gt;
      &lt;input type="text" class="form-control" name="LastName" id="LastName" placeholder="Last Name"required=""&gt;
    &lt;/div&gt;
  
  
      &lt;div class="form-group"&gt;
      &lt;label for="Age"&gt;How old are you?&lt;/label&gt;
      &lt;input type="text" class="form-control"  name="Age" id="Age" placeholder="Age"required=""&gt;
    &lt;/div&gt;
  
      &lt;div class="form-group"&gt;
      &lt;label for="Email"&gt;Email:&lt;/label&gt;
      &lt;input type="email" class="form-control"  name="Email" id="Email" placeholder="Yes@SModels.org" required=""&gt;
    &lt;/div&gt;
  
      &lt;h4Please Select if your a Student?&lt;/h4&gt;
      &lt;div&gt;&lt;small class="form-text text-muted"&gt;
          Select all that apply.
  
      &lt;div class="custom-control custom-checkbox"&gt;
      &lt;input type="checkbox" class="custom-control-input"  name="Student" id="Student" value="Yes" &gt;
      &lt;label class="custom-control-label" for="Student"&gt;Student&lt;/label&gt;
  &lt;/div&gt;
  
      &lt;h4&gt;Please agree to the following:&lt;/h4&gt;
  
      &lt;div class="custom-control custom-checkbox"&gt;
      &lt;input type="checkbox" class="custom-control-input"  name="Agree18" id="Agree18" value="Yes" required="" &gt; 
      &lt;label class="custom-control-label" for="Agree18"&gt;I can prove I am 18 years or older. I am legal age to participate according to my country. Proof may be required by law.&lt;/label&gt;
  &lt;/div&gt;
  &lt;div&gt;&lt;small&gt;
        All information will be held strictly confidential in accordance with our disclosure policy which can be requested.    
      &lt;/small&gt;&lt;/div&gt; &lt;br&gt;
  &lt;center&gt;
  
      &lt;div class="submit"&gt;
      &lt;button type="submit" name="submit" class="btn btn-primary"&gt;Send &lt;i class="fa fa-lock"&gt;&lt;/i&gt;&lt;/button&gt;
  &lt;/div&gt;
      &lt;/center&gt; &lt;br&gt;&lt;br&gt;&lt;br&gt;
      &lt;/div&gt;
  
      &lt;/form&gt;  
      &lt;/div&gt;
  ~~~~~~
  I hope to have a working example code for the latest phpmailer 6.0.7 and I have read a lot of documents.  I want a good working example for 2019 since there is a lot of old phpmailer.
  </code></pre>