我有以下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> </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脚本,到目前为止还没有人将帖子数据发送到我的邮箱。我已经允许在更改php脚本之间花费几个小时,因为我知道它们可以延迟到达但没有运气。
答案 0 :(得分:0)
您使用的是localhost吗?
PHP中的mail()函数不能在localhost中工作。
尝试添加此内容:
ini_set(&#39; display_errors&#39;,1);
如果未使用
启用,则启用php中的错误答案 1 :(得分:0)
您检查了垃圾邮件文件夹?
尝试发送邮件到本网站的地址:https://www.mail-tester.com/
它将显示您(如果收到)您应该在电子邮件配置中更改的内容,应添加的内容(标题)等,因为邮件服务器具有过滤器。您的发送电子邮件可能是错误的:)
答案 2 :(得分:0)
你需要解决两个小错误。错误如下:
$ Body。= $ name; 而不是 $ Body。= $ Name;
$ EmailFrom =“email”; 而不是 $ EmailFrom =“$ email”;
注意:put $email to email or give some value to variable $email
答案 3 :(得分:0)
如果您使用的是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不匹配,则邮件将转到SPAM文件夹。
同时检查您的服务器IP是否未列入黑名单