I made a form that request your name, last name, email and motivation for applying for a internship. I made a PHP file for sending all the information with PHPmailer.
The funny things that's happening is, that lastname isn't sent with name, email and motivation($comments).
Sample code from the form.
<div id="contactform">
<form method="post" action="sendmail.php">
<p><label for="name">Naam:*</label> <input type="text" name="name" id="name" tabindex="1" /></p>
<p><label for="lastname">Achternaam:*</label> <input type="text" name="lastname" id="lastname" tabindex="2" /></p>
<p><label for="email">Email:*</label> <input type="text" name="email" id="email" tabindex="3" /></p>
<p><label for="comments">Motivatie:*</label> <textarea name="comments" id="comments" cols="12" rows="6" tabindex="4"></textarea></p>
</br><br>
<p><input type="submit" class="button radius medium" name="submit" id="submit" value="submit" tabindex="5" /></p>
And this is the sample code from the sendmail.php
<?php
$name = trim($_POST['name']);
$lastname = trim($_POST['lastname']);
$email = $_POST['email'];
$comments = $_POST['comments'];
$site_owners_email = 'info@inperfection.nl'; // Replace this with your own email address
$site_owners_name = 'CloudMe'; // replace with your name
if (strlen($name) < 2) {
$error['name'] = "Please enter your name";
}
if (strlen($lastname) < 2) {
$error['lastname'] = "Trolololololololo.";
}
if (!preg_match('/^[a-z0-9&\'\.\-_\+]+@[a-z0-9\-]+\.([a-z0-9\-]+\.)*+[a-z]{2}/is', $email)) {
$error['email'] = "Please enter a valid email address";
}
if (strlen($comments) < 4) {
$error['comments'] = "Please leave a comment.";
}
if (!$error) {
require_once('phpMailer/class.phpmailer.php');
$mail = new PHPMailer();
$mail->From = $email;
$mail->Subject = "Contact Form";
$mail->AddAddress($site_owners_email, $site_owners_name);
$mail->Body = "Naam :$name Achternaam:$lastname Email:$email Motivatie:$comments";
$mail->Send();
echo "<div data-alert class='alert-box success'>Thanks " . $lastname . ". Your message has been sent.<a href='#' class='close' onclick='clearForms()'>×</a></div>";
} # end if no error
else {
$response = (isset($error['name'])) ? "<div class='alert-box alert'>" . $error['name'] . "</div>
" : null;
$response = (isset($error['lastname'])) ? "<div class='alert-box alert'>" . $error['lastname'] . "</div>
" : null;
$response .= (isset($error['email'])) ? "<div class='alert-box alert'>" . $error['email'] . "</div>
" : null;
$response .= (isset($error['comments'])) ? "<div class='alert-box alert'>" . $error['comments'] . "</div>" : null;
echo $response;
} # end if there was an error sending
?>
So, the variable is set for $lastname. But am I overlooking something?
Help would be great.