I am having a difficult time with the syntax of PHP when trying to customize the layout of content that is sent using a PHP form. I am trying to display each input on a different line in an email... Below is my PHP code:
<?php
// Section 1.
if( $_POST['name_here_goes'] == '' ){
// Section 2.
if ( !empty($_POST['firstName']) && !empty($_POST['lastName']) && !empty($_POST['emailAddress']) ) {
$to = '####@############.com';
$subject = 'NEW Contact Form';
$message = $_POST['firstName'] "\n\n" $_POST['lastName'];
$headers = 'From: ' . $_POST['emailAddress'] . ' ' . "\r\n" .
'Reply-To: ' . $_POST['emailAddress'] . '' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
// Section 3.
if ( mail($to, $subject, $message, $headers) ) {
echo 'Email sent. Congrats!';
}
}else{
echo 'Please fill all the info.';
}
}else{
// Section 4.
echo 'Spam detected!';
}
Here is my HTML code:
<form name="contact" method="post" action="sell.php">
<div>
<input type="text" name="firstName" value="" placeholder="First Name" />
<input type="text" name="lastName" value="" placeholder="Last Name" />
<input type="text" name="emailAddress" value="" placeholder="Email" />
</div>
<div>
<input type="text" class="robotic" name="name_here_goes" value="" />
<input type="submit" name="submit" value="Submit"/>
</div>
</form>