title: Send mail via SMTP?
body: <p>I have a form on my website where people can join events. The code behind it  works in this way:</p>
  <ol>
  <li><p>All info is saved in a database. This part works fine.</p>
  </li>
  <li><p>The second part of the code send out an email to me and to the user with the info he entered (same info as saved in the database)</p>
  </li>
  </ol>
  <p>The issue is that these emails are sent unauthenticated through a default email on the hosting account. I had to modify the script to force SMTP authentication with a valid email under my hosting account to fix the error. Right now the script sends out the email but it ends in spamfilter with all ISPs so the user never receive the email.</p>
  <p>I have no idea of how to do, or create the codes so the script use SMTP authentication. Below is the codes I have so fare. Can someone help me?</p>
  <pre><code>&lt;?
  // SEND OUT EMAIL PART
  // COPY SEND TO MY SELF
  $to = &quot;my@email.com&quot;; 
  $from = $_REQUEST['email'] ; 
  $name = $_REQUEST['name'] ; 
  $headers = &quot;From: $from&quot;; 
  $subject = &quot;Thanks!&quot;; 
  
  $fields = array(); 
  $fields{&quot;name&quot;} = &quot;Name&quot;; 
  $fields{&quot;address&quot;} = &quot;Address&quot;; 
  $fields{&quot;phone&quot;} = &quot;Phone&quot;; 
  $fields{&quot;email&quot;} = &quot;E-mail addesse&quot;; 
  
  $body = &quot;INFO:\n\n&quot;; foreach($fields as $a =&gt; $b){  $body .= sprintf(&quot;%20s: %s\n&quot;,$b,$_REQUEST[$a]); } 
  
  
  // SEND TO THE USER
  $headers2 = &quot;From: my@email.com&quot;; 
  $subject2 = &quot;THANKS!&quot;; 
  
  $fields2 = array(); 
  $from = $_REQUEST['email'] ; 
  $name = $_REQUEST['name'] ; 
  $headers = &quot;From: $from&quot;; 
  $subject = &quot;Thanks!&quot;; 
  
  $body2 = &quot;
  
  TEXT TO EMAIL RECEIVER
  
  \n\n&quot;; foreach ($fields2 as $a =&gt; $b){  $body2 .= sprintf(&quot;%20s: %s\n&quot;,$b,$_REQUEST[$a]); } 
  
  // ERROR MESSAGES
  if($from == '') {print &quot;MISSING EMAIL ADDRESS.&quot;;} 
  else { 
  if($name == '') {print &quot;MISSING NAME&quot;;} 
  else { 
  $send = mail($to, $subject, $body, $headers); 
  $send2 = mail($from, $subject2, $body2, $headers2); 
  if($send) 
  {header( &quot;Location: http://mysite/send.php&quot; );} 
  else 
  {print &quot;MISSING EMAIL ADDRESS ALL FILDS MUST BE FILLED!&quot;; } 
  }
  }
  ?&gt;
  </code></pre>