title: PHP/HTML form data to send as an email from my GMAIL account
body: <p>I am trying to send an email to myself when someone fills in the form on my web page. My form looks like this:</p>
  
  <pre><code>    &lt;form id="contactForm" action="#" method="post"&gt;
                  &lt;fieldset&gt;                      
                      &lt;p&gt;
                          &lt;label for="name" &gt;Name&lt;/label&gt;
                          &lt;input name="name"  id="name" type="text" class="form-poshytip" title="Enter your full name" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;label for="email" &gt;Email&lt;/label&gt;
                          &lt;input name="email"  id="email" type="text" class="form-poshytip" title="Enter your email address" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;label for="web"&gt;Website&lt;/label&gt;
                          &lt;input name="web"  id="web" type="text" class="form-poshytip" title="Enter your website" /&gt;
                      &lt;/p&gt;
                      &lt;p&gt;
                          &lt;label for="comments"&gt;Message&lt;/label&gt;
                          &lt;textarea  name="comments"  id="comments" rows="5" cols="20" class="form-poshytip" title="Enter your comments"&gt;&lt;/textarea&gt;
                      &lt;/p&gt;
                      &lt;!-- send mail configuration --&gt;
                      &lt;input type="hidden" value=EMAIL" name="to" id="to" /&gt;
                      &lt;input type="hidden" value="Email received from Website" name="subject" id="subject" /&gt;
                      &lt;input type="hidden" value="send-mail.php" name="sendMailUrl" id="sendMailUrl" /&gt;
                      &lt;!-- ENDS send mail configuration --&gt;
  
                      &lt;p&gt;&lt;input type="button" value="Send" name="submit" id="submit" /&gt; &lt;span id="error" class="warning"&gt;Message&lt;/span&gt;&lt;/p&gt;
                  &lt;/fieldset&gt;
  
              &lt;/form&gt;
  </code></pre>
  
  <p>and the PHP i have looks like this:</p>
  
  <pre><code>&lt;?php
  //vars
  $subject = $_POST['subject'];
  $to = explode(',', $_POST['to'] );
  
  $from = $_POST['email'];
  
  //data
  $msg = "NAME: "  .$_POST['name']    ."&lt;br&gt;\n";
  $msg .= "EMAIL: "  .$_POST['email']    ."&lt;br&gt;\n";
  $msg .= "WEBSITE: "  .$_POST['web']    ."&lt;br&gt;\n";
  $msg .= "COMMENTS: "  .$_POST['comments']    ."&lt;br&gt;\n";
  
  //Headers
  $headers  = "MIME-Version: 1.0\r\n";
  $headers .= "Content-type: text/html; charset=UTF-8\r\n";
  $headers .= "From: &lt;".$from. "&gt;" ;
  
  $smtp = Mail::factory('smtp', array(
          'host' =&gt; 'ssl://smtp.gmail.com',
          'port' =&gt; '465',
          'auth' =&gt; true,
          'username' =&gt; 'EMAIL',
          'password' =&gt; 'PASSWORD'
      ));
  
  $mail = $smtp-&gt;send($to, $headers, $msg);
  ?&gt;
  </code></pre>
  
  <p>Where EMAIL and PASSWORD are replaced with the values....</p>
  
  <p>Can anyone advise on what to do?</p>