收到表单提交,但内容字段为空。
将"$_POST['Email']"
改为"$_GET['Email']"
已评论论坛上的其他10篇文章并排除故障3小时。
HTML代码
<form action="callform.php" method="post" class="request-form ftco-
animate">
<div class="form-group">
<input type="text" name="name" class="form-control" placeholder="Full
Name">
</div>
<div class="form-group">
<input type="text" name="email" class="form-control" placeholder="Email
Address">
</div>
<div class="form-group">
<div class="form-field">
<div class="select-wrap">
<div class="icon"><span class="ion-ios-arrow-down"></span></div>
<select name="dropdown" id="Selection" class="form-control">
<option value="">Select Your Services</option>
<option value="">White Paper</option>
<option value="">Brown Paper</option>
<option value="">Black Paper</option>
<option value="">Red Paper</option>
<option value="">Yellow Paper</option>
<option value="">Orange Paper</option>
<option value="">Blue Paper</option>
<option value="">Green Paper</option>
<option value="">Purple Paper</option>
<option value="">Clear Plastic</option>
<option value=""></option>
</select>
</div>
</div>
</div>
<div class="form-group">
<input type="text" name="phone" class="form-control" placeholder="Phone">
</div>
<div class="form-group">
<textarea type="text" name="message" id="message" cols="30" rows="2"
class="form-control" placeholder="Message"></textarea>
</div>
<div class="form-group">
<input type="submit" value="Submit" class="btn btn-primary py-3 px-4"
name="submit">
</div>
</form>
PHP
<?php
$EmailFrom = ".$email";
$mailTo = "my_email";
$Subject = "New Request";
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$txt = "You have received a Request from ".$name.".\n\n".$message;
mail($mailTo, $Subject, $dropdown, $message, $headers);
/* Redirect visitor to the thank you page */
header('Location: ""?msg=success');
?>
这是我收到的:
来自:CGI-Mailer至:[email protected]主题:新的呼叫请求
您收到了来自的请求。
请检查一下
您使用了错误的邮件格式:这是一封邮件(收件人,主题,邮件,标题,参数);
$mailTo = "my_email";
$subject = "New Request";
$name = $_POST['name'];
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$txt = "You have received a Request from ".$name." ".$message;
mail($mailTo, $subject, $txt, $headers);
/* Redirect visitor to the thank you page */
header('Location: ""?msg=success');
?>
您的mailTo函数中有一个额外的参数。
这个:
mail($mailTo, $Subject, $dropdown, $message, $headers);
应该成为
mail($mailTo, $Subject, $message, $headers);
您将$ dropdown的值作为消息发送,$ message作为标题发送。该函数没有抛出错误,因为它接受可选的参数值
如果您继续使用$ _POST,则其余代码看起来很好,因为您在表单定义中使用该方法
请使用此代码发送您正在使用的表单电子邮件
$body = 'Name:-'.$_POST['name'];
$body .= 'Email:-'.$_POST['email'];
$body .= 'Services:-'.$_POST['dropdown'];
$body .= 'Phone:-'.$_POST['phone'];
$body .= 'Message:-'.$_POST['message'];
$subject = "Your email subject here";
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$headers .="From: [email protected] \r\n";
$to_email = "Your email address here";
if(@mail($to_email,$subject,$body,$headers))
{
echo 'email send sucessfully';
}
else
{
echo "Message could not be sent.";
exit();
}
如我所见,提交后,表单字段值正确发送。我没有发现任何重大问题。但是你应该以这种方式捕获字段数据之前做一些基本的验证 -
<?php
if (isset($_POST['submit'])){
$EmailFrom = "your from email goes here";
$Subject = "New Request";
$name = $_POST['name'];
$mailTo = 'mail to email goes here';
$email = $_POST['email'];
$dropdown = $_POST['dropdown'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$headers = 'MIME-Version: 1.0' . "\r\n";
// Additional headers
$headers = 'From: ' .$EmailFrom. "\r\n";
$headers .= 'Reply-To: '.$email. "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$txt = "You have received a Request from ".$name.".\n\n".$message;
mail($mailTo, $Subject, $txt, $headers);
/* Redirect visitor to the thank you page */
header('Location: ""?msg=success');
}
?>
但是,当我进行上述更正时,您的邮件功能包含错误的参数。如果需要,你也可以将其他字段连接到$txt
变量并添加html标记。