PDA

Click to See Complete Forum and Search --> : PHP not wanting to work


reuber1
10-09-2007, 02:59 AM
Never touched PHP before, but it seems to be the way to get a contact form on my site.

Well, after getting the PHP file uploaded, I can enter the contact criteria and I get a basic page that says that the e-mail has been sent (which is ugly, but I'll deal with that later), but my hosted e-mail account gets nothing. I tried it with my GMail account in the PHP file, and entered data in the form, and that didn't work either. Basically, it says the message is being sent, but nothing arrives in the specified inbox.


Here's the necessary code in contact.html:

<form method="POST" action="mailer.php">
Name<br>
<input type="text" name="name" size="19"><br>
<br>
E-Mail<br>
<input type="text" name="email" size="19"><br>
<br>
Message<br>

<textarea rows="9" name="message" cols="30"></textarea>
<br>
<br>
<input type="submit" value="Submit" name="submit">
</form>


Here's the PHP file, mailer.php:


<?php
if(isset($_POST['submit'])) {

$to = "reuber1@hotmail.com";
$subject = "Website Inquiry";
$name_field = $_POST['name'];
$email_field = $_POST['email'];
$message = $_POST['message'];

$body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message";

echo "Data has been submitted to $to!";
mail($to, $subject, $body);

} else {

echo "The message could not be sent.";

}
?>

FYI, the e-mail I'm actually using is the e-mail on my site, not the crappy spam maintenance Hotmail account I have.

Any ideas why this isn't working? I'm stumped.

GraphixNPrint
10-09-2007, 03:56 AM
<form action="" enctype="multipart/form-data" method="post">
<div align="center">
<input type="Hidden" name="required" value="fname,email"><br>
<table width="600" border="0" cellspacing="2" cellpadding="2">
<tr>
<td>
<div align="right">
<font size="-2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>Full Name:</b></font></div>
</td>
<td><input type="Text" name="fname"></td>
</tr>
<tr>
<td>
<div align="right">
<font size="-2" face="Arial,Helvetica,Geneva,Swiss,SunSans-Regular"><b>Company:</b></font></div>
</td>
<td><input type="Text" name="company"></td>
</tr>
<tr>
<td></td>
<td>
<div align="left">
<input type="Submit" value="Send Request"></div>
</td>
</tr>
</table>
</div>
</form>


example post action page:

<?
$to = "emailaddress"; $subject = "Whatever subject";
$from = john@johndoe or the email address in the form;
$body = " $fname $company ";
mail($to,$subject,$body,"FROM: ".$from);
?>

This is just a general example and provides NO SECURITY, and anytime google or any other search engine hits the page it will send a blank email... you need to include some form of authentication that a human clicked the submit button. :)

from your code it should work,, however you did not SET the variable "_POST" and without that being set to a positive the for will assume a negative response and nada.

GraphixNPrint
10-09-2007, 04:05 AM
well the board ate the first half of the reply I posted; and I dont wanna fight with it.... so if you have probelms rueber ask here or call me off my homepage anytime from 9a-7p in the US

reuber1
10-09-2007, 04:25 AM
"from your code it should work,, however you did not SET the variable "_POST" and without that being set to a positive the for will assume a negative response and nada."

So do I have to declare that first, or something? I don't know the first thing about PHP, I am working off the tutorial found here:
http://www.kirupa.com/web/php_contact_form2.htm

GraphixNPrint
10-09-2007, 04:43 AM
using your original form, and please remember I am no where being a teacher, the following should work as your "mailer.php" file.

<?
$to = "reuber1@hotmail.com";
$subject = "Website Inquiry";
$name_field = $name;
$email_field = $email;
$message = $message;
$body = "From: $name\n E-Mail: $email\n Message:\n $message";
echo "Data has been submitted to $to!";
mail($to, $subject, $body);
?>

I would include an if statement as you were attempting such as:
if method="POST"; then do this

but this is a start for you and should get your form working, and you can learn PHP from there (trust me its fun ... I learned it because I had to and not cause I wanted to) :)

reuber1
10-09-2007, 04:48 AM
Roger that. I'll give that a shot and see what happens. Coding is not my forte.

Thanks for the help man.

Drazan
11-01-2007, 11:38 AM
That simple code will work, however it will also work for every spam injector out there. And you don't want your server/hosting shut down for spam.

What else you want to look at is called Captcha. that is where the person submitting the form will need to ender a random bit of characters before hitting submit. It will stop quite a bit of the "bot" produced spammers. But not the ones who do actually go to your page to exploit the form.

Another idea is to have a contact database. These can even be a privately viewed "guestbook" type script. Or just find an actual contact database script. Again use the Captcha for the form submission. But the actual base of the script won't use email and won't have spam bot attacks.

Jade