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";
}
}
?>
PHP email issue
Moderator: General Moderators
- mecha_godzilla
- Forum Contributor
- Posts: 375
- Joined: Wed Apr 14, 2010 4:45 pm
- Location: UK
Re: PHP email issue
One of the problems you've got is that you aren't calling the mail() function correctly - the format is
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
Code: Select all
mail($email_to_address, $subject, $message, $headers);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