PHP 表格似乎没有发送

PHP form does not seem to be sending

我有以下 HTML:

 <form id="enquiryform" name="enquiryform" action="contact.php" method="post" >
        <table border="0" cellspacing="2" cellpadding="4" align="left">
        <tr>
        <td>Name</td>
        <td><input name="efcontactname" type="text" class="fields" value=""  /></td>
        </tr>
        <tr>
        <td>Company Name</td>
        <td><input name="efcompanyname" type="text" class="fields" value="" /></td>
        </tr>
        <tr>
        <td>Postcode</td>
        <td><input name="efpostcode" type="text" class="fields" value="" /></td>
        </tr>
        <tr>
        <td>Telephone Number</td>
        <td><input name="eftel" type="text" class="fields" value="" /></td>
        </tr>
        <tr>
        <td>Email Address</td>
        <td><input name="efemailaddress" class="fields" type="text" value="" /></td>
        </tr>
        <tr>
        <td>Re:</td>
        <td>
        <select name="efenquirytype">
        <option value="">Please indicate the nature of your enquiry</option>
        <option value=""></option>
        <option value="Sales">Sales</option>
        <option value="Hire">Hire</option>
        <option value="Parts">Parts</option>
        <option value="Service">Service</option>
        <option value="General">General</option>
        </select>
        </td>
        </tr>
        <tr>
        <td>Comments</td>
        <td><textarea name="efcomments" class="fields"class="fields" cols="30" rows="4"></textarea></td>
        </tr>
        <tr>
        <td>&nbsp;</td>
        <td>
        <input type="submit" value="Send Enquiry" />
        </td>
        </tr>
        </table>
        </form>

和 contact.php 内的以下 php:

<?php

$EmailFrom = "$email";
$EmailTo = "myemail@mydomain.com";
$Subject = "Website Enquiry";
    $name     = Trim(stripslashes($_POST['efcontactname']));

    $company  = Trim(stripslashes($_POST['efcompanyname']));

    $postcode = Trim(stripslashes($_POST['efpostcode']));

    $phone    = Trim(stripslashes($_POST['eftel']));

    $email    = Trim(stripslashes($_POST['efemailaddress']));

    $re       = Trim(stripslashes($_POST['efenquirytype']));

    $comments = Trim(stripslashes($_POST['efcomments']));

// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $Name;
$Body .= "\n";
$Body .= "Company: ";
$Body .= $company;
$Body .= "\n";
$Body .= "Postcode: ";
$Body .= $postcode;
$Body .= "\n";
$Body .= "Phone: ";
$Body .= $phone;
$Body .= "\n";
$Body .= "email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Re: ";
$Body .= $re;
$Body .= "\n";
$Body .= "Comments: ";
$Body .= $comments;
$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

显然,我已将电子邮件更改为变量,所以这不是我没有收到它的原因。谁能阐明我哪里出错了?我想知道下拉菜单是否会导致它失败但给我一条成功消息?这是我尝试的第三个 php 脚本,到目前为止 none 已将 post 数据发送到我的电子邮件。我在更改 php 脚本之间留出了几个小时的时间,因为我知道它们可能会延迟到达,但运气不好。

您使用的是本地主机吗?

PHP 中的 mail() 函数在 localhost 中不起作用。

尝试添加这个:

ini_set('display_errors', 1);

如果未使用

启用,它会在 php 中启用错误

您检查过垃圾邮件文件夹了吗?

尝试将邮件发送到此网站上的地址:https://www.mail-tester.com/

它会告诉你(如果收到)你应该在你的电子邮件配置中改变什么,你应该添加什么(headers)等等,因为邮件服务器有过滤器。您发送的电子邮件可能是错误的:)

下面有两个小错误需要fix.mistakes:

$Body .= $name; 而不是 $Body .= $Name;

$EmailFrom = "email"; 而不是 $EmailFrom = "$email";

注:put $email to email or give some value to variable $email

如果您使用的是 Microsoft windows 系统,则不会发送电子邮件。因为它没有安装电子邮件系统。

如果您使用的是linux系统,请确保您已经安装了电子邮件服务器软件

如果您确定这两个都有效,请尝试从 mail() 中删除 if 语句

就这样

<?php
if (mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>")){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=index.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>

也检查没有 if 语句是否有效。

不要忘记选中电子邮件帐户中的垃圾邮件框。 如果发件人域 A DNS 条目与托管 php 文件的服务器 IP 不匹配,邮件将转到垃圾邮件文件夹。

同时检查你的服务器IP是否不在黑名单