title: swiftmailer contact form required fields
body: <p>I have built a contact form on a website which is handled by swiftmailer. At the moment it sends correctly with an image attachment and some input fields. How do i make some of the fields "required" and output an error message on those if left empty? Is this something that needs to happen before the swiftmailer library comes into it?</p>
  
  <p>Apologies if this is simple stuff but im new to PHP and cant find a quick answer to this anywhere</p>
  
  <pre><code>&lt;?php
  
  $_SESSION["post"] = $_POST; 
  $name = $_POST["Name"]; $email = $_POST["Email"]; $phone = $_POST["Phone"]; $dob = $_POST['DOBDay'] ."\t" .$_POST['DOBMonth'] ."\t" .$_POST['DOBYear'];$address = $_POST['AddressLine1'] ."\n" .$_POST['AddressLine2'] ."\n" .$_POST['PostCode'];$experience = $_POST["Experience"];$height = $_POST["Height"]; $size = $_POST["DressSize"];$bra = $_POST["Bra"];$waist = $_POST["Waist"];$hipwidest = $_POST["HipWidest"];$bicep = $_POST["Bicep"];$thigh = $_POST["Thigh"];$shoe = $_POST["Shoe"];    
  
  require_once 'lib/swift_required.php';
  
  // Create the Transport
  $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, "ssl")
  -&gt;setUsername('xxx@gmail.com')
  -&gt;setPassword('xxx');
  
  
  
  // Create the Mailer using your created Transport
  $mailer = Swift_Mailer::newInstance($transport);
  
  // Create a message
  $message = Swift_Message::newInstance('Be A Model application: Girls') 
  
  // Set the From address with an associative array
  -&gt;setFrom(array($email =&gt; $name))
  
  // Set the To addresses with an associative array
  -&gt;setTo(array('xxx@xxx.com', 'xxx@xxx.com' =&gt; 'contact test'))
  
  // Give it a body
  -&gt;setBody('Name: ' .$name ."\n"
  .'Email: ' .$email ."\n"
  .'Phone: ' .$phone ."\n"
  .'Address: ' .$address ."\n"
  .'DOB: ' .$dob ."\n"
  .'Experience: ' .$experience ."\n"
  .'Height: ' .$height ."\n"
  .'Dress Size: ' .$size ."\n"
  .'Bra: ' .$bra ."\n"
  .'Waist: ' .$waist ."\n"
  .'Hip at Widest: ' .$hipwidest ."\n"
  .'Bicep: ' .$bicep ."\n"
  .'Thigh: ' .$thigh ."\n"
  .'Shoe Size: ' .$shoe ."\n" );
  
  
  // And optionally an alternative body
  //-&gt;addPart('&lt;q&gt;Here is the message itself&lt;/q&gt;', 'text/html');
  
  // Attachment  
  $message-&gt;attach(
  Swift_Attachment::fromPath($_FILES['fileatt']['tmp_name'])-&gt;setFilename($_FILES['fileatt']['name'])
  );
  
  // Send the message
  $result = $mailer-&gt;send($message);
  
  if ($result)
  {
  header('Location: http://www.modelmeasures.co.uk/thankyou.html');
  }
  echo $result;
  
  ?&gt;
  </code></pre>