I have a form in my page, with 4 fields: name, email, purpose and comments. However, when I submit, the POST encoded request contains only three - name, email and comments.
The purpose field is EXACTLY the same as Name, with the same attributes. This is really baffling. Anything I am doing wrong?
<form method="post" action="http://myserver.com/contact.php" name="contactform" id="contactform" role="form">
<fieldset id="contact_form">
<label for="name">
<input type="text" name="name" id="name" placeholder="Name" required />
</label>
<label for="email">
<input type="email" name="email" id="email" placeholder="Email" required />
</label>
<label for="purpose">
<input type="text" name="purpose" id="purpose" placeholder="Purpose" required />
</label>
<label for="comments">
<textarea name="comments" id="comments" placeholder="Details"></textarea>
</label>
<input type="submit" class="btn btn-black btn-default" id="submit" value="Submit" />
</fieldset>
</form>
Here is the PHP
<?php
header('Access-Control-Allow-Origin: *');
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
require($_SERVER['DOCUMENT_ROOT']."/mail_support/class.phpmailer.php");
$form_name = $_POST['name'];
$form_email= $_POST['email'];
$form_purpose= $_POST['purpose'];
$form_comments= $_POST['comments'];
$mail = new PHPMailer();
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPDebug = 3;
$mail->Host = "cp-dd-us-3.webhostbox.net"; // SMTP
$mail->SMTPAuth = true;
$mail->Username = "***@website.com";
$mail->Password = "secret";
$mail->SMTPSecure = "ssl";
$mail->Port = 465;
$mail->From = "***@website.com";
$mail->FromName = 'My Website';
$mail->AddAddress("to_email","to_name");
$mail->addReplyTo($form_email);
$mail->isHTML(true);
$mail->Subject = $form_name . "[" . $form_email . "]" . " for purpose" . $form_purpose;
$mail->Body = "<b>" . $form_purpose . "</b> <br /><br />" . $form_comments ;
$mail->AltBody = $form_purpose . "\n\n" . $form_comments;
$mail->WordWrap = 50;
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>