title: insert into database, then send email
body: <p>I'm forced to use PHP against my will, so I'll need some help with this.</p>
  
  <p>After googling, I have the following basic code and am wondering whether it is OK.</p>
  
  <p>This is for a pre-launch "coming soon" page, where user enter an email address, which gets inserted into a mysql database and gets a reply message. This is all happening on a hosted server.</p>
  
  <p>Ideally, I want to generate some HTML with images etc and send that HTML in the email body. Does someone have any idea how to do that in PHP?</p>
  
  <pre><code>&lt;?php
      $servername = "localhost:3306";
      $username = "userblah";
      $password = "passblah";
      $dbname = "blah";
  
      // Create connection
      $conn = new mysqli($servername, $username, $password, $dbname);
      // Check connection
      if ($conn-&gt;connect_error) {
          die("Connection failed: " . $conn-&gt;connect_error);
      }
  
      $sql = "INSERT INTO prelaunch_users (email)
      VALUES ($_GET['email'];)";
  
      if ($conn-&gt;query($sql) === TRUE) {
          echo "New record created successfully";
      } else {
          echo "Error: " . $sql . "&lt;br&gt;" . $conn-&gt;error;
      }
  
      $conn-&gt;close();
  
      $to      = $_GET['email'];
      $subject = 'Welcome';
      $message = 'hello';
      $headers = 'From: blah@blah.co.nz' . "\r\n" .
          'Reply-To: blah@blah.co.nz' . "\r\n" .
          'X-Mailer: PHP/' . phpversion();
  
      mail($to, $subject, $message, $headers);
  ?&gt; 
  </code></pre>
  
  <p>I think I'd need a username and password for the hosted mail server there probably as well.</p>
  
  <p>Thank you</p>
  
  <p>Paul</p>