PHP newbie needs help with website contact form script
Moderator: General Moderators
-
blueluna86
- Forum Newbie
- Posts: 9
- Joined: Wed Jul 29, 2009 8:07 pm
Re: PHP newbie needs help with website contact form script
The link to the form on the website is http://www.alisonborden.com/k8dollar/pages/contact.htm
The reason for the javascript "protect.js" is that I was looking for a way to put a contact form on the website without anyone being able to steal the "mailto" email address and spam me. The solution I found online said that one way to avoid this would be to use the php script I am using, and add to it that javascript file, which is supposed to switch out the "no-javascript.php" (which isn't real) for "safemail.php". The article I was reading said that you do this switcheroo so that no one can go into your html or php script and take out the email address. I think my problem is that I don't know how this works really, so I am having problems troubleshooting it. How can I test it without the javascript? I don't know how to call the php file directly from the html, but I will look that up. If I call the php file directly from the html, is it less secure than using that javascript?
Thanks for your help.
The reason for the javascript "protect.js" is that I was looking for a way to put a contact form on the website without anyone being able to steal the "mailto" email address and spam me. The solution I found online said that one way to avoid this would be to use the php script I am using, and add to it that javascript file, which is supposed to switch out the "no-javascript.php" (which isn't real) for "safemail.php". The article I was reading said that you do this switcheroo so that no one can go into your html or php script and take out the email address. I think my problem is that I don't know how this works really, so I am having problems troubleshooting it. How can I test it without the javascript? I don't know how to call the php file directly from the html, but I will look that up. If I call the php file directly from the html, is it less secure than using that javascript?
Thanks for your help.
-
blueluna86
- Forum Newbie
- Posts: 9
- Joined: Wed Jul 29, 2009 8:07 pm
Re: PHP newbie needs help with website contact form script
Still getting nowhere, here are my most recent attempts:
Redid the form html to this to try calling the php script without javascript:
I thought maybe it would be simpler if I made the value and the variable the same name, so I changed to this:
Redid the form html to this to try calling the php script without javascript:
Code: Select all
<form id="contactform" action="safemail.php" enctype="text/plain" method="post">
<table width="400" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>First Name </td>
<td><input type="text" name="first_name" /></td>
</tr>
<tr>
<td>Last Name </td>
<td><input type="text" name="last_name" /></td>
</tr>
<tr>
<td>Email address </td>
<td><input type="text" name="email" /></td>
</tr>
<tr>
<td>Phone number </td>
<td><input type="text" name="phone" /></td>
</tr>
<tr>
<td>In which area of work are you interested? (Check all that apply) </td>
<td><input type="checkbox" name="residential" value="checkbox" />
Residential<br />
<input type="checkbox" name="commercial" value="checkbox" />
Commercial<br />
<input type="checkbox" name="landscape" value="checkbox" />
Landscape</td>
</tr>
<tr>
<td>Type your question or comment to the right. Please be specific, but concise. </td>
<td><textarea name="comments" cols="20" rows="5" id="inquiry"></textarea></td>
</tr>
<tr>
<td colspan="2"><input id="submit" name="Submit" type="button" value="Submit" />
</td>
</tr>
</table>
</form>Code: Select all
<?php
// Pick up the form data and assign it to variables
$first_name = $_POST['first_name'];
$last_name = $_POST['last_name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$residential = $_POST['residential'];
$commercial = $_POST['commercial'];
$landscape = $_POST['landscape'];
$comments = $_POST['comments'];
// Build the email (replace the address in the $to section with your own)
$to = 'bordengraphic@yahoo.com';
$subject = "k8dollar.com Contact Form Submission";
$message = "New message from your contact form at k8dollar.com: $first_name $last_name Area of Interest: $residential $commercial $landscape ... Comments: $comments ... Contact Info: $email $phone";
$headers = "From: $email";
// Send the mail using PHPs mail() function
mail($to, $subject, $message, $headers);
// Redirect
header("Location: formsubmit.htm");Re: PHP newbie needs help with website contact form script
Well, it isn't really safer, since someone could just submit directly to safemail.php, completely bypassing the form. I think you'd be better off having a captcha image or something. That's what captcha is designed for 
Try not redirecting back. Try putting echo 'hello'; or something, just to make sure the script is actually running. Also, turn on error reporting if it isn't already.
Try not redirecting back. Try putting echo 'hello'; or something, just to make sure the script is actually running. Also, turn on error reporting if it isn't already.
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP newbie needs help with website contact form script
I found your problem
should be
hope this works
Code: Select all
<html>
<td colspan="2"><input id="submit" name="Submit" type="button" value="Submit" />
</html >Code: Select all
<html>
<td colspan="2"><input id="submit" name="Submit" type="submit" value="Submit" />
</html >“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
Re: PHP newbie needs help with website contact form script
Wow, nice spot.
-
blueluna86
- Forum Newbie
- Posts: 9
- Joined: Wed Jul 29, 2009 8:07 pm
Re: PHP newbie needs help with website contact form script
social_experiment wrote:I found your problem
should beCode: Select all
<html> <td colspan="2"><input id="submit" name="Submit" type="button" value="Submit" /> </html >
Code: Select all
<html> <td colspan="2"><input id="submit" name="Submit" type="submit" value="Submit" /> </html >hope this works
Thank you! That did get the email to send. However ... it did not pick up the form data. Here is the result: An email with no "from" (sender) and this message:
Code: Select all
New message from your contact form at k8dollar.com: Area of Interest: ... Comments: ... Contact Info:Thanks,
Alison
-
blueluna86
- Forum Newbie
- Posts: 9
- Joined: Wed Jul 29, 2009 8:07 pm
Re: PHP newbie needs help with website contact form script
I did some testing and I think the problem is with the $_POST part that is supposed to pick up the form information. If I enter just a string as a value, for example: the PHP will echo back $first_name. But if I put in it's blank. Is the syntax wrong or something? Or is there some other reason it is not assigning the form data to variables?
Thank you,
Alison
Code: Select all
$first_name = "Alison";Code: Select all
$first_name = $_POST["first_name"];Thank you,
Alison
- social_experiment
- DevNet Master
- Posts: 2793
- Joined: Sun Feb 15, 2009 11:08 am
- Location: .za
Re: PHP newbie needs help with website contact form script
Try changing :
to :
Im not sure why the enctype attribute is stopping the data ( it could be something else ) but once i removed it, the form submits the data that is entered into the fields.
You might want to use the following code with the checkboxes :
and then use the following php code :

Code: Select all
<html>
<form id="contactform" action="safemail.php" enctype="text/plain" method="post">
</html>
Code: Select all
<html>
<form id="contactform" action="safemail.php" method="post">
</html>
You might want to use the following code with the checkboxes :
Code: Select all
<html>
<tr>
<td>In which area of work are you interested? (Check all that apply) </td>
<td><input type="checkbox" name="area[]" value="residential" />
Residential<br />
<input type="checkbox" name="area[]" value="Commercial" />
Commercial<br />
<input type="checkbox" name="area[]" value="Landscape" />
Landscape</td>
</tr>
</html>
Code: Select all
<?php
if ( is_array($_POST['area']) ) {
foreach ( $_POST['area'] as $area );
// will return the 'value' of the selected checkbox
}
?>
“Don’t worry if it doesn’t work right. If everything did, you’d be out of a job.” - Mosher’s Law of Software Engineering
-
straightman
- Forum Commoner
- Posts: 48
- Joined: Sun Apr 19, 2009 5:20 am
Re: PHP newbie needs help with website contact form script
I don't understand why you need that javascript to send an email if you are using PHP. As you know, nobody is going to be able to see your email address because they will not be able to see your php code. forget about safe mail and fakemail.
Additionally you dont even need two pages, one for the html form and the other for the php processing as you can have all in one single page.
I could write the whole thing, but it is too long and sincerely, I am not that motivated. Your options are:
find a ready made script on the web, there are many.
If you are really desperate and there is no way you are coming on, contact me and i ll do the whole thing for you.
regards
Alvaro
=======================================================================================
Additionally you dont even need two pages, one for the html form and the other for the php processing as you can have all in one single page.
I could write the whole thing, but it is too long and sincerely, I am not that motivated. Your options are:
find a ready made script on the web, there are many.
If you are really desperate and there is no way you are coming on, contact me and i ll do the whole thing for you.
regards
Alvaro
=======================================================================================
blueluna86 wrote:The link to the form on the website is http://www.alisonborden.com/k8dollar/pages/contact.htm
The reason for the javascript "protect.js" is that I was looking for a way to put a contact form on the website without anyone being able to steal the "mailto" email address and spam me. The solution I found online said that one way to avoid this would be to use the php script I am using, and add to it that javascript file, which is supposed to switch out the "no-javascript.php" (which isn't real) for "safemail.php". The article I was reading said that you do this switcheroo so that no one can go into your html or php script and take out the email address. I think my problem is that I don't know how this works really, so I am having problems troubleshooting it. How can I test it without the javascript? I don't know how to call the php file directly from the html, but I will look that up. If I call the php file directly from the html, is it less secure than using that javascript?
Thanks for your help.
-
blueluna86
- Forum Newbie
- Posts: 9
- Joined: Wed Jul 29, 2009 8:07 pm
Re: PHP newbie needs help with website contact form script
Thank you! You're right, it was the enctype. I got the same result from removing it. Basically, that fixes my problem, but I will also try your recommendation about the checkboxes. Thanks so much! I really appreciate everyone's help with this post, too. Mystery solved!social_experiment wrote:
Im not sure why the enctype attribute is stopping the data ( it could be something else ) but once i removed it, the form submits the data that is entered into the fields.