Page 1 of 1

PHP email issue

Posted: Fri Apr 30, 2010 4:41 pm
by zerbe32
I'm new at this and at my wits end..
I have this PHP form that goes with my contact form (as you can tell). When I upload the PHP to the web and click the submit button on my contact form, I get a blank page that comes up. This blank page is suppose to say message sent and plus on top of that I don't get the message in the email. I'm totally lost. I've tried different configurations and I'm not sure what I can do to fix this. If there's anyone who could take a look at this and tell me what's going on I would absolutely appreciate it.

-Zerbe32

<?php
if (isset($_POST['submit'])){
$to = "example@hotmail.com";
$subject = "You have a message";
$name_field = $_POST['Name'];
$email_field = $_POST['Email'];
$tel_field = $_POST['Tel'];
$message = $_POST['Message'];

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


echo "Data has been submitted to $to!";
if (mail($to, $subject, $body)){
} else {
echo "Message Sent";
}
}
?>

Re: PHP email issue

Posted: Fri Apr 30, 2010 6:22 pm
by mecha_godzilla
One of the problems you've got is that you aren't calling the mail() function correctly - the format is

Code: Select all

mail($email_to_address, $subject, $message, $headers);
but your script is sending the headers first, then the message afterwards. A good example of a working script can be found here:

http://uk.php.net/manual/en/function.mail.php

Also, the if() statement at the end of your script is not quite right, because mail() should return TRUE if it completes (and so you'd want to echo out your "message sent" text out at this point and not if the if() test fails.)

If you need any further help please say so.

HTH,

Mecha Godzilla