我的表单有问题。当我点击提交时,所有细节都通过我的电子邮件发送,但问题是:我收到2封电子邮件,1封在我的收件箱中,1封在我的垃圾邮件中。
我真的不知道我的代码出了什么问题..
任何建议都将受到高度赞赏。
这是我的send_app.php代码
<?php
// get posted data into local variables
$EmailFrom = "webmaster";
$EmailTo = "sjb_jparedes@yahoo.com";
$Subject = "Contact us";
$name = $_POST['name'];
$address=$_POST['address'];
$month =$_POST['month'];
$day =$_POST['day'];
$year =$_POST['year'];
$home =$_POST['home'];
$mobile =$_POST['mobile'];
$contact =$_POST['contact'];
$relationship =$_POST['relationship'];
$course =$_POST['course'];
$hours =$_POST['hours'];
// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";
$Body .= "Month: ";
$Body .= $month;
$Body .= "\n";
$Body .= "Day: ";
$Body .= $day;
$Body .= "\n";
$Body .= "Year: ";
$Body .= $year;
$Body .= "\n";
$Body .= "Home No.: ";
$Body .= $home;
$Body .= "\n";
$Body .= "Mobile: ";
$Body .= $mobile;
$Body .= "\n";
$Body .= "Contact Person: ";
$Body .= $contact;
$Body .= "\n";
$Body .= "Relationship: ";
$Body .= $relationship;
$Body .= "\n";
$Body .= "Course: ";
$Body .= $course;
$Body .= "\n";
$Body .= "Hours: ";
$Body .= $hours;
$Body .= "\n";
$headers = "From: ".$EmailFrom."" ;
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
// redirect to success page
if (mail($EmailTo, $Subject, $Body, $headers)){
header( "Location: application.php" );
}
?>
答案 0 :(得分:3)
简单回答:您发送了2封电子邮件:
// First E-Mail
$success = mail($EmailTo, $Subject, $Body, $headers);
// Second E-Mail
if (mail($EmailTo, $Subject, $Body, $headers)){
header( "Location: application.php" );
}
只需删除第一行,或者 - 如果需要返回值 - 请写下:
// Send E-Mail
$success = mail($EmailTo, $Subject, $Body, $headers);
if ($success){
header( "Location: application.php" );
}
答案 1 :(得分:2)
嗯,您在代码中调用mail
两次:
// send email
$success = mail($EmailTo, $Subject, $Body, $headers);
// redirect to success page
if (mail($EmailTo, $Subject, $Body, $headers)){
当然,邮件会被发送两次......
答案 2 :(得分:1)
你要两次打电话!替换此代码
// redirect to success page
if (mail($EmailTo, $Subject, $Body, $headers)){
与
if ($success){
答案 3 :(得分:1)
// redirect to success page
if (mail($EmailTo, $Subject, $Body, $headers)){
这个条件实际上会执行另一个发送,如果成功则执行
header( "Location: application.php" );