3

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>

enter image description here

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.';
}
?>
Jay
  • 81
  • 4
  • my freind, contact.php – arif_suhail_123 Nov 11 '15 at 02:50
  • debug: `print_r($_POST);` –  Nov 11 '15 at 02:52
  • 1
    who the hell upvoted this ??, its not even a complete question – arif_suhail_123 Nov 11 '15 at 02:53
  • what do you mean by *"The purpose field is EXACTLY the same as Name, with the same attributes."*?? **Post your PHP**, or this will close using an *educated guess* link. – Funk Forty Niner Nov 11 '15 at 02:58
  • @Fred-ii- did you upvoted it twice lol – arif_suhail_123 Nov 11 '15 at 03:00
  • 1
    @arif_suhail_123 hahaha, yeah right lol! *au contraire mon frère* ;-) – Funk Forty Niner Nov 11 '15 at 03:00
  • @Fred-ii-, I thought the screengrab from Chrome was enough to show that parameter was never sent from the browser itself, PHP was never a problem. I have posted the PHP anyway. Cheers! – Jay Nov 11 '15 at 15:07
  • @Fred-ii- i know you closed the question that time, when he did not post his php code, now he posted his php code, it definately not unidenfied problem, i checked his form, i am able to get the value, i dont know why he cant. – arif_suhail_123 Nov 13 '15 at 02:09
  • 1
    @arif_suhail_123 I reopened it, but I sense OP still isn't showing us full code, not when I see ID's. Anyway, good luck. I won't be offering assistance for this question. – Funk Forty Niner Nov 13 '15 at 02:16
  • @Fred-ii- you are nice person thanks for reopenning, i lost 30 minutes of life try to solving it, i can not find any problem, i think you are right, its not a full code, but may be i am wrong, wish you luck as well. – arif_suhail_123 Nov 13 '15 at 02:20
  • 1
    @arif_suhail_123 I was just going to mention earlier, if you saw something I wasn't. So, if you didn't see anything, nor have I, then I highly doubt anyone else will. It's anybody's ballgame now. However this part of the question: *"The purpose field is EXACTLY the same as Name, with the same attributes."* is quite questionable and I have no idea what the guy means by that. I sense/smell missing JS here, seeing other parts of the code. Anyway, whoever wants to take a shot at it, are welcome to it. I won't be spending anymore time than I already have. – Funk Forty Niner Nov 13 '15 at 02:25
  • @arif_suhail_123, thanks for your help. No, there isn't any Javascript hidden. I mean "exactly" in the sense that I copy-paste the Name field, label and input tag included, into my HTML code. I've wasted hours trying to debug, no use. – Jay Nov 14 '15 at 11:17
  • I removed the field altogether from my website out of frustration, but if anybody is up for a challenge, let me know and I will re-enable the field and provide you the address so you can test. Chrome debug tools reports only three POST parameters sent, even though there are clearly four fields. – Jay Nov 14 '15 at 11:19
  • dear i took your original form, and copy and pasted theese lines from question, `$form_name = $_POST['name']; $form_email= $_POST['email']; $form_purpose= $_POST['purpose']; $form_comments= $_POST['comments'];` and than i used echo i get the all the `purpose` the one is giving you problem. I did not check other, if you no javascript, than problem is further down, you are getting the value, try this. you will see for your self that you are getting the value. – arif_suhail_123 Nov 15 '15 at 02:03

0 Answers0