...

View Full Version : Contact form



Kineas
11-01-2009, 10:59 AM
I'm trying to make a contact form that will e-mail me what the user has input. My code all seems to work fine, but then I never receive an e-mail. This is what I've got so far. I am hosting it on a webserver when trying it, and I have put my actual e-mail address in the code, I just took it out so no one would see it on here, in case someone was gonna say that's why it's not working lol.

contact.php

<form method="POST" action="mailer.php">
Name<BR>
<input type="text" name="name" size="19"><br>
<BR><BR>
E-Mail<BR>
<input type="text" name="email" size="19"><br>
<BR><BR>
Message<BR>
<textarea rows="9" name="message" cols="30"></textarea>
<BR>
<BR>
<input type="submit" value="Submit" name="submit">
</form>

mailer.php

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

$to = "me@me.com";
$subject = "Form Tutorial";
$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 "blarg!";

}
?>

met
11-01-2009, 11:41 AM
code looks fine, looks like its probably a server problem

you can try



mail($to, $subject, $body, "From: you@yoursite.com");


and setting the from header.

you can also check if the email is accepted FOR delivery. mail() can't tell you if the email is received however.



if(mail($to, $subject, $body, "From: you@yoursite.com"))
{
echo 'email was accepted for delivery..';
} else {
echo 'somethings not right.';
}

Kineas
11-01-2009, 02:45 PM
Thanks for the reply. The website is for a university assignment, and I'm using the university's web server to host it, so maybe they've disabled outoing e-mail? Ah well, as long as they see the code's fine, I should get the marks for it.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum