[英]Contact Form Has No Content
收到表单提交,但内容字段为空。
已将"$_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收件人:mailpost@mymail.com主题:新呼叫请求
您已收到来自的请求。
请检查一下
您使用了错误的邮件格式:这是正确的一封邮件(收件人,主题,消息,标题,参数);
$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');
?>
如我所见,提交后,表单字段值正确发送。 我没有发现任何重大问题。 但是您应该在以这种方式捕获字段数据之前进行一些基本的验证-
<?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标记。
您的mailTo函数中有一个额外的参数。
这个:
mail($mailTo, $Subject, $dropdown, $message, $headers);
应该成为
mail($mailTo, $Subject, $message, $headers);
您将senddrop的$ 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: noreply@yourdomainname.com \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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.