Forum Moderators: coopster

Message Too Old, No Replies

malfunction of contact form

         

cmabill

1:15 pm on May 16, 2016 (gmt 0)

5+ Year Member



I am not sure this is the right place for my post since I know nothing about webdesign.

I has a website, which is very simple and works well except the contact form, I experienced a lot of spam because it seems the validation of form is not functioning well.

I tested it myself, the validation works well under windows XP, I am not sure for other browser, this is some code I got from website so I really don't know where is the problems.

below is the PHP part of the contact form

<body>
<?php
$field_firstname = $_POST['firstname'];" ".$_POST['lastname'];
$field_emailaddress= $_POST['emailaddress'];
$field_telepohone = $_POST['telephone'];
$field_country = $_POST['country'];
$field_business = $_POST['business'];
$field_comments = $_POST['comments'];

$mail_to = 'info@abc.com';
$subject = 'Message from a site visitor '.$field_name;

$body_message .= 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$_POST['emailaddress']."\n";
$body_message .= 'Message: \n'.$_POST['emailaddress']."\n";
$body_message .= $_POST['telephone']."\n";
$body_message .= $_POST['country']."\n";
$body_message .= $_POST['business']."\n";
$body_message .= $_POST['comments'];

$headers = 'From: '.$_POST['emailaddress'].'\r\n';
$headers = 'Reply-To: '.$_POST['emailaddress'].'\r\n';

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Thank you for the message. We will contact you shortly.');

<!--
window.location.href = "http://www.abc.com/index.html";
//-->

</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed. Please check the items required');

<!--
window.location.href = "http://www.zooqc.com/contact.html";
//-->

</script>
<?php
}
?>
</body>
</html>


below is the Dreamweaver part of contact from

<div id="formplace">
<form action="contact.php" method="post" name="formplace" target="_blank" class="email" id="formplace" onsubmit="MM_validateForm('firstname','','R','lastname','','R','emailaddress','','NisEmail','comments','','R');return document.MM_returnValue">
You could also fill in below form and send it to us. we will get back to you as soon as possible.<br /><br />
First name: <input name="firstname" type="text" id="firstname" style="height:13px ; position:absolute; left:110px;" maxlength="25" /><br /><br />

Last name: <input name="lastname" type="text" id="lastname" style="height:13px ; position:absolute; left:110px;" maxlength="25" /><br /><br />

Email Address: <input name="emailaddress" type="text" id="emailaddress" style="height:13px ; position:absolute; left:110px;" maxlength="25" /><br /><br />

Telephone: <input name="telephone" type="text" id="telephone" style="height:13px ; position:absolute; left:110px;" maxlength="25" /><br /><br />

Country: <select name="country"style="height:20px ; position:absolute; left:110px;">
<option>Australia</option>
<option>Austria</option>
<option>Belgium</option>
<option>Czech Republic</option>
<option>Denmark</option>
<option>Finland</option>
<option>France</option>
<option>Germany</option>
<option>Greece</option>
<option>Hungary</option>
<option>Italy</option>
<option>Netherlands</option>
<option>Norway</option>
<option>Poland</option>
<option>Romania</option>
<option>Russia</option>
<option>Spain</option>
<option>Sweden</option>
<option>Switzerland</option>
<option>United Kingdom</option>
<option>Canada</option>
<option>Mexico</option>
<option>United States of America</option>
<option>Argentina</option>
<option>Brazil</option>
<option>New Zealand</option>
<option>Egypt</option>
<option>Iran</option>
<option>Israel</option>
<option>Kuwait</option>
<option>Saudi Arabia</option>
<option>Turkey</option>
<option>Japan</option>
<option>South Korea</option>
<option>Vietnam</option>
<option>other</option>
</select><br /><br />

Business:<select name="business"style="height:20px ; position:absolute; left:110px;">
<option>wholesale</option>
<option>retail</option>
<option>industrial</option>
<option>services</option>
<option>distributor</option>
<option>manufacturer</option>
<option>importer</option>
<option>other</option>
</select><br /><br />

Comments:<textarea name="comments" style="position:absolute; left:110px; height:150px; width:330px;" cols="38" rows="5" id="comments"></textarea><br />
<br />

<input name="submit" type="submit" id="submit" style="position:absolute; left:110px; bottom:20px;" onclick="MM_validateForm('firstname','','R','lastname','','R','emailaddress','','RisEmail','telephone','','NisNum','comments','','R');return document.MM_returnValue" value="Submit" />
<br />
</p>
</form>
</div>


pls kindly hekp me with this, which is very important to me to apply something. thank you

cmabill

5:12 am on May 17, 2016 (gmt 0)

5+ Year Member



anyone could help this?

Andy Langton

6:27 am on May 17, 2016 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Two problems:

- You're blindly accepting user input without any validation. The form is likely vulnerable to 'injection' attacks. For instance, your headers include whatever the user supplies as an email address:

$headers = 'From: '.$_POST['emailaddress'].'\r\n';
$headers = 'Reply-To: '.$_POST['emailaddress'].'\r\n';


If I supply a
$_POST['emailaddress']
containing a newline and additional header, I can likely add/change recipients, change the message and more. E.g., I submit
From:me@example.com%0ATo:hijack@example.com


- Validation doesn't check that anything has been entered correctly - it is only checking whether the mail() command returns true. You should check that each field contains expected values.

Can you also clarify what the specific problem is you're having? If you're receiving a lot of spam through the form, then while you need to fix the above, it's a separate problem. E.g. you might need to add a captcha or check for common spam text.

cmabill

6:55 am on May 17, 2016 (gmt 0)

5+ Year Member



Dear Andy

thank you so much for your input, I am not sure that I can make it clear or not since this is not my professional. I DID get email that shows validation is not checking at all. as I specified, I got this code from internet and change it a little bit. I have no any knowledge on codes or languages.

what I need is validation function properly and check the expected values, like name, email, message etc, I am sorry that I can attached the pictures of the emails I received, pls see below for your ref.

Sender: moo.abc@yourhostingaccount.com
Subject: message from a site visitor
content
From:
E-mail:
Message: \n


I am start up and don't have enough budget to hire a expert for this website, but I DO need this simple website works properly so that I could pass the brand registration from Amazon. I don't know this is a big project or some easy task, it's highly appreciated if you could recommend a place where I could pay $10 to get this settled. thank you for your comments.

cmabill

7:00 am on May 17, 2016 (gmt 0)

5+ Year Member



I don't think I need a captcha for this form because it's too complicated to me, just want to improve it so that the validation works properly. thank you

cmabill

4:14 am on May 19, 2016 (gmt 0)

5+ Year Member



no one knows?