title: How to integrate SMTP auth into a sendmail PHP script
body: <p>Bear in mind, I am new to PHP</p>
  
  <p>Hi, i'm having trouble sending SMTP mail from a script that only uses sendmail.</p>
  
  <p>The below code is my original old code that works but that gives a warning on Gmail when viewed. It says this message can not be verified. I'm trying to send the user their credentials from a password reset form (I will be implementing this on the registration form as well).</p>
  
  <p>Original Code:</p>
  
  <pre><code>    ##### Mail functions #####
  
      function sendLostPasswordEmail($myusername, $email, $newpassword)
      {
  
      global $domain;
      $message = "
      You have requested a new password on example.com
  
      Here is Your new password information:
  
      username:  $myusername
      password:  $newpassword
  
  
      Regards,
      example Administration
      ";
  
      if (sendMail($email, "Your password has been reset.", $message, "noreply@example.com"))
      {
      return true;
      } else
      {
      return false;
      }
  
  
      }
  
      function sendMail($to, $subject, $message, $from)
      {
  
  
      $from_header = "From: $from";
  
      if (mail($to, $subject, $message, $from_header))
      {
      return true;
      } else
      {
      return false;
      }
      return false;
      }
  
      function sendActivationEmail($myusername, $password, $uid, $email, $actcode)
      {
      global $domain;
      $link = "https://example.com/includes/activate.php?uid=$uid&amp;actcode=$actcode";
      $message = "
      Thank you for registering on https://example.com,
  
      Your account information:
  
      username:  $myusername
      password:  $password
  
      Please click the link below to activate your account.
  
      $link
  
      Regards
      $domain Administration
      ";
  
      if (sendMail($email, "Please activate your account.", $message, "noreply@example.com"))
      {
      return true;
      } else
      {
      return false;
      }
      }
  
      ?&gt;
  </code></pre>
  
  <p>Code to implement (I think)</p>
  
  <pre><code>    require_once "php/Mail/mail.php";
  
      $from = "Example Company &lt;noreply@example.com&gt;";
      $to = "&lt;&gt;";
      $subject = "Your Password Has Been Reset";
      $body = "$message";
  
      $host = "mail.example.com";
      $port = "465";
      $username = "noreply@example.com";
      $password = "***";
  
      $headers = array ('From' =&gt; $from,
      'To' =&gt; $to,
      'Subject' =&gt; $subject);
      $smtp = Mail::factory('smtp',
      array ('host' =&gt; $host,
      'port' =&gt; $port,
      'auth' =&gt; true,
      'username' =&gt; $username,
      'password' =&gt; $password));
  
      $mail = $smtp-&gt;send($to, $headers, $body);
  </code></pre>
  
  <p>I believe the 2nd code snippet will fit in with the original somewhere, however, I have been trying for several hours to solve this problem to no avail. I appreciate any help, if you need to see the actual password recovery form code or think I could improve my question please tell me.</p>