title: Replacing mail() script with SMTP script
body: <p>PHP's <code>mail()</code> function has stopped sending my emails. I talked with my service provider and they said I have to use SMTP however i am not professional php developer. They tried to give a little help and they provided me with a script which sends email to me when a user submit a form, but my old form used to send email to me of the clent data as well as a confirmation email email to the client.</p>
  
  <p>The new script i have manged some how to send a confirmation email for the client, but I don't know how send email with this script, can you tell me what I should add to make it work?</p>
  
  <pre><code>if(isset($_POST['submit']))
  
  {
  
  $title         = $_POST['title'];
  $name          = $_POST['name'];
  $surname       = $_POST['surname'];
  $phone         = $_POST['phone'];
  $visitor_email = $_POST['email'];
  $address       = $_POST['address'];
  $postcode      = $_POST['postcode'];
  $state         = $_POST['us'];
  $details       = $_POST['details'];
  $reasons       = $_POST['re'];
  $content       = $_POST['message'];
  
  require("class.phpmailer.php");
  
  $mail = new PHPMailer();
  
  //Your SMTP servers details
  
  // set mailer to use SMTP
  $mail-&gt;IsSMTP();
  
  // specify main and backup server or localhost / your mail server yourmailserver.com
  $mail-&gt;Host = "xxxxxx.example.com";  
  
  // turn on SMTP authentication
  $mail-&gt;SMTPAuth = true;     
  
  // SMTP username
  $mail-&gt;Username = "me@xxxxx.com";  
  
  $mail-&gt;Password = "**********"; // SMTP password
  //It should be same as that of the SMTP user
  
  $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
  
  //$mail-&gt;From = $mail-&gt;Username;    //Default From email same as smtp user
  $mail-&gt;FromName = "Admin";
  
  //Email address where you wish to receive/collect those emails.
  $mail-&gt;AddAddress($visitor_email, ""); 
  
  $mail-&gt;WordWrap = 50;// set word wrap to 50 characters
  $mail-&gt;IsHTML(true);// set email format to HTML
  
  $mail-&gt;Subject = 'You have mail from: www.example.com';
  
  
  // ** Build the Message
  $message = "&lt;h4&gt;&lt;b&gt;We received your query&lt;/b&gt;&lt;/h4&gt;&lt;br/&gt;&lt;br/&gt;";
  $message .="Thankyou for contacting example.net.&lt;br/&gt;";
  $message .="&lt;br&gt;";
  $message .="Regards,&lt;br/&gt;";
  $message .="admin";
  
  
  
  $mail-&gt;Body    = $message;
  
  //header("Location: thank-you.html");
  if(!$mail-&gt;Send())
  {
      header('Location: thank-you.html');
    // echo "Message could not be sent. &lt;p&gt;";
    // echo "Mailer Error: " . $mail-&gt;ErrorInfo;
     exit;
  }
  
  header('Location: thank-you.html');
  
  
  
  }
  else{
      header('Location:  contact-us.html');   
  }
  ?&gt;
  
  
  
  
  // ******** Second update 
  &lt;?
  ob_start();
  if(isset($_POST['submit']))
  
  {
  
  $title         = $_POST['title'];
  $name          = $_POST['name'];
  $surname       = $_POST['surname'];
  $phone         = $_POST['phone'];
  $visitor_email = $_POST['email'];
  $address       = $_POST['address'];
  $postcode      = $_POST['postcode'];
  $state         = $_POST['us'];
  $details       = $_POST['details'];
  $reasons       = $_POST['re'];
  $content       = $_POST['message'];
  
  require("class.phpmailer.php");
  
  $mail = new PHPMailer();
  
  //Your SMTP servers details
  
  // set mailer to use SMTP
  $mail-&gt;IsSMTP();
  
  // specify main and backup server or localhost / your mail server yourmailserver.com
  $mail-&gt;Host = "xxx.example.net";  
  
  // turn on SMTP authentication
  $mail-&gt;SMTPAuth = true;     
  
  // SMTP username
  $mail-&gt;Username = "*****@example.net";  
  
  $mail-&gt;Password = "********"; // SMTP password
  //It should be same as that of the SMTP user
  
  $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
  
  //$mail-&gt;From = $mail-&gt;Username;    //Default From email same as smtp user
  $mail-&gt;FromName = "Admin vueproperty";
  
  $mail-&gt;AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
  //$mail-&gt;AddCC($_POST['email']); // ** Client email
  $mail-&gt;WordWrap = 50;// set word wrap to 50 characters
  $mail-&gt;IsHTML(true);// set email format to HTML
  
  $mail-&gt;Subject = 'You have mail from: www.exmple.net';
  
  
  // ** Build the Message
  $message = "&lt;h4&gt;&lt;b&gt;We received your query&lt;/b&gt;&lt;/h4&gt;&lt;br/&gt;&lt;br/&gt;";
  $message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.&lt;br/&gt;";
  $message .="&lt;br&gt;";
  $message .="Regards,&lt;br/&gt;";
  $message .="The example Team";
  
  
  
  $mail-&gt;Body    = $message;
  
  //header("Location: thank-you.html");
  
  if($mail-&gt;Send())
  {
      $body  = "Name: $name&lt;br/&gt;";
      $body .= "Phone: $phone&lt;br/&gt;";
      $body .= "Email: $visitor_email&lt;br/&gt;";
      $mail-&gt;AddAddress('xphpxmysql@gmail.com', "MINE");
      if($mail-&gt;Send()){
          header('Location: thank-you.html');
          exit;
      }
  }
  
  
  
  
  
  }
  
  ?&gt;
  // ******** Third update 
  &lt;?
  ob_start();
  if(isset($_POST['submit']))
  
  {
  
  $title         = $_POST['title'];
  $name          = $_POST['name'];
  $surname       = $_POST['surname'];
  $phone         = $_POST['phone'];
  $visitor_email = $_POST['email'];
  $address       = $_POST['address'];
  $postcode      = $_POST['postcode'];
  $state         = $_POST['us'];
  $details       = $_POST['details'];
  $reasons       = $_POST['re'];
  $content       = $_POST['message'];
  
  require("class.phpmailer.php");
  
  $mail = new PHPMailer();
  
  //Your SMTP servers details
  
  // set mailer to use SMTP
  $mail-&gt;IsSMTP();
  
  // specify main and backup server or localhost / your mail server yourmailserver.com
  $mail-&gt;Host = "xxx.example.net";  
  
  // turn on SMTP authentication
  $mail-&gt;SMTPAuth = true;     
  
  // SMTP username
  $mail-&gt;Username = "*****@example.net";  
  
  $mail-&gt;Password = "********"; // SMTP password
  //It should be same as that of the SMTP user
  
  $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
  
  //$mail-&gt;From = $mail-&gt;Username;    //Default From email same as smtp user
  $mail-&gt;FromName = "Admin vueproperty";
  
  $mail-&gt;AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
  //$mail-&gt;AddCC($_POST['email']); // ** Client email
  $mail-&gt;WordWrap = 50;// set word wrap to 50 characters
  $mail-&gt;IsHTML(true);// set email format to HTML
  
  $mail-&gt;Subject = 'You have mail from: www.exmple.net';
  
  
  // ** Build the Message
  $message = "&lt;h4&gt;&lt;b&gt;We received your query&lt;/b&gt;&lt;/h4&gt;&lt;br/&gt;&lt;br/&gt;";
  $message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.&lt;br/&gt;";
  $message .="&lt;br&gt;";
  $message .="Regards,&lt;br/&gt;";
  $message .="The example Team";
  
  
  
  $mail-&gt;Body    = $message;
  
  //header("Location: thank-you.html");
  
  if($mail-&gt;Send())
  {
      $body = "Name: " . $name . "&lt;br/&gt;"; 
      $body .= "Phone: " . $phone . "&lt;br/&gt;"; 
      $body .= "Email: ". $visitor_email . "&lt;br/&gt;"; 
      $mail-&gt;body = $body; 
      $mail-&gt;AddAddress('xphpxmysql@gmail.com', "MINE"); 
      if($mail-&gt;Send())
      {
          header('Location: thank-you.html'); 
          exit;
      }
  
  }
  
  
  
  
  }
  
  ?&gt;
  </code></pre>
  
  <p>//<strong><em>*</em>***</strong> The fifth update</p>
  
  <pre><code>&lt;?
  ob_start();
  if(isset($_POST['submit']))
  
  {
  
  $title         = $_POST['title'];
  $name          = $_POST['name'];
  $surname       = $_POST['surname'];
  $phone         = $_POST['phone'];
  $visitor_email = $_POST['email'];
  $address       = $_POST['address'];
  $postcode      = $_POST['postcode'];
  $state         = $_POST['us'];
  $details       = $_POST['details'];
  $reasons       = $_POST['re'];
  $content       = $_POST['message'];
  
  require("class.phpmailer.php");
  
  $mail = new PHPMailer();
  
  //Your SMTP servers details
  
  // set mailer to use SMTP
  $mail-&gt;IsSMTP();
  
  // specify main and backup server or localhost / your mail server yourmailserver.com
  $mail-&gt;Host = "xxx.example.net";  
  
  // turn on SMTP authentication
  $mail-&gt;SMTPAuth = true;     
  
  // SMTP username
  $mail-&gt;Username = "*****@example.net";  
  
  $mail-&gt;Password = "********"; // SMTP password
  //It should be same as that of the SMTP user
  
  $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
  
  //$mail-&gt;From = $mail-&gt;Username;    //Default From email same as smtp user
  $mail-&gt;FromName = "Admin vueproperty";
  
  $mail-&gt;AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
  //$mail-&gt;AddCC($_POST['email']); // ** Client email
  $mail-&gt;WordWrap = 50;// set word wrap to 50 characters
  $mail-&gt;IsHTML(true);// set email format to HTML
  
  $mail-&gt;Subject = 'You have mail from: www.exmple.net';
  
  
  // ** Build the Message
  $message = "&lt;h4&gt;&lt;b&gt;We received your query&lt;/b&gt;&lt;/h4&gt;&lt;br/&gt;&lt;br/&gt;";
  $message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.&lt;br/&gt;";
  $message .="&lt;br&gt;";
  $message .="Regards,&lt;br/&gt;";
  $message .="The example Team";
  
  
  
  $mail-&gt;Body    = $message;
  
  
  if($mail-&gt;Send())
  {
      $body = "Name: " . $name . "&lt;br/&gt;"; 
      $body .= "Phone: " . $phone . "&lt;br/&gt;"; 
      $body .= "Email: ". $visitor_email . "&lt;br/&gt;"; 
      $mail-&gt;Body = $body; 
      $mail-&gt;AddAddress('xphpxmysql@gmail.com', "MINE"); 
      if($mail-&gt;Send())
      {
          header('Location: thank-you.html'); 
          exit;
      }
  
  }
  </code></pre>
  
  <p>}</p>
  
  <pre><code>?&gt;
  </code></pre>
  
  <p>//// <strong><em>*</em>**<em>*</em></strong> Sixth update NOW it's working it's working </p>
  
  <pre><code>    &lt;?
      ob_start();
      if(isset($_POST['submit']))
  
      {
  
      $title         = $_POST['title'];
      $name          = $_POST['name'];
      $surname       = $_POST['surname'];
      $phone         = $_POST['phone'];
      $visitor_email = $_POST['email'];
      $address       = $_POST['address'];
      $postcode      = $_POST['postcode'];
      $state         = $_POST['us'];
      $details       = $_POST['details'];
      $reasons       = $_POST['re'];
      $content       = $_POST['message'];
  
      require("class.phpmailer.php");
  
      $mail = new PHPMailer();
  
      //Your SMTP servers details
  
      // set mailer to use SMTP
      $mail-&gt;IsSMTP();
  
      // specify main and backup server or localhost / your mail server yourmailserver.com
      $mail-&gt;Host = "xxx.example.net";  
  
      // turn on SMTP authentication
      $mail-&gt;SMTPAuth = true;     
  
      // SMTP username
      $mail-&gt;Username = "*****@example.net";  
  
      $mail-&gt;Password = "********"; // SMTP password
      //It should be same as that of the SMTP user
  
      $redirect_url = "http://".$_SERVER['SERVER_NAME']; //Redirect URL after submit the form
  
      //$mail-&gt;From = $mail-&gt;Username;    //Default From email same as smtp user
      $mail-&gt;FromName = "Admin vueproperty";
  
      $mail-&gt;AddAddress($visitor_email, ""); //Email address where you wish to receive/collect those emails.
      //$mail-&gt;AddCC($_POST['email']); // ** Client email
      $mail-&gt;WordWrap = 50;// set word wrap to 50 characters
      $mail-&gt;IsHTML(true);// set email format to HTML
  
      $mail-&gt;Subject = 'You have mail from: www.exmple.net';
  
  
      // ** Build the Message
      $message = "&lt;h4&gt;&lt;b&gt;We received your query&lt;/b&gt;&lt;/h4&gt;&lt;br/&gt;&lt;br/&gt;";
      $message .="Thank you for contacting example.net.  A property consultant will be in contact with you asap.&lt;br/&gt;";
      $message .="&lt;br&gt;";
      $message .="Regards,&lt;br/&gt;";
      $message .="The example Team";
  
  
  
      $mail-&gt;Body    = $message;
  
      $mail-&gt;Send();
          $mail-&gt;ClearAllRecipients();
          $body = "Name: " . $name . "&lt;br/&gt;"; 
          $body .= "Phone: " . $phone . "&lt;br/&gt;"; 
          $body .= "Email: ". $visitor_email . "&lt;br/&gt;"; 
          $mail-&gt;Body = $body; 
          $mail-&gt;AddAddress('xphpxmysql@gmail.com', ""); 
          if($mail-&gt;Send())
          {
          $mail-&gt;ClearAllRecipients();
          header('Location: thank-you.html'); 
          exit;
      }
  
  }
  </code></pre>