开发者

Broken PHP contact form script

开发者 https://www.devze.com 2023-01-19 18:47 出处:网络
I\'m trying to make a contactform. And somehow it won\'t work. I tried to send a email just with the mail()-function and that works.

I'm trying to make a contactform. And somehow it won't work. I tried to send a email just with the mail()-function and that works. So I'm doing something wrong and I don't know what.

When you click on the submit button, I refer to the mailer.php file. Both file are in the same folder.

&l开发者_高级运维t;?php
if(isset($_POST['sendButton']))
{
 $to = "contact@domain.com";
 $subject = "Contactformulier Portfolio";
 $name_field = $_POST['yourName'];
 $email_field = $_POST['yourEmail'];
 $message = $_POST['yourMessage'];

 $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 "There has been some error, try again please!";
}
?>


Is your form button named "sendButton"? <input type='submit' name='sendButton' /> If not, there's your culprit.


Can you provide your HTML as well?

EDIT:

$_POST indeces are defined by the name attribute on your input elements. As you have only defined an id field on your submit input element, the condition you are checking is never met (and thus the mail is never send). Add the name attribute to your submit input element like this:


Without seeing all your code, my guess is that the condition for mailing is never met because there is no value set for the submit button. Try making the condition for emailing like this:

if($_POST) {
  Mail Here
} else {
  error case
}
0

精彩评论

暂无评论...
验证码 换一张
取 消