简体   繁体   English

损坏的PHP联系人表单脚本

[英]Broken PHP contact form script

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. 我试图仅通过mail()函数发送电子邮件,并且可以正常工作。 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. 当您单击提交按钮时,我指的是mailer.php文件。 Both file are in the same folder. 两个文件都在同一个文件夹中。

<?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"? 您的表单按钮名为“ sendButton”吗? <input type='submit' name='sendButton' /> If not, there's your culprit. <input type='submit' name='sendButton' />如果不是,那是您的罪魁祸首。

Can you provide your HTML as well? 您还可以提供HTML吗?

EDIT: 编辑:

$_POST indeces are defined by the name attribute on your input elements. $ _POST索引由输入元素上的name属性定义。 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). 由于仅在Submit输入元素上定义了id字段,因此永远不会满足您要检查的条件(因此,永远不会发送邮件)。 Add the name attribute to your submit input element like this: 将name属性添加到您的Submit输入元素中,如下所示:

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
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM