想通过PHP发送电子邮件和获得感谢页面.但是$HEADER和$HEADERS不能一起工作


Want to send e-mail and get thankyou page through PHP. But $HEADER and $HEADERS not working together

这是我使用的形式的PHP代码。我想与$headers附加它,并希望它重定向到感谢页面时,表单提交。我收到了感谢页面,但没有收到电子邮件。

<?php
$action = $_SERVER['PHP_SELF'];
    $fname = $_POST['fname'];
    $phone = $_POST['phone'];
    $e_mail = $_POST['e_mail'];
    $service = $_POST['service'];
    $maker = $_POST['maker'];
    $model = $_POST['model'];
    $year = $_POST['year'];
    $message = $_POST['message'];
$to = 'reckless.sam@gmail.com';
$headers = 'From: Micheal Key <reply@locallockman.com>';
$subject = 'Customer Service Request';
$body = 'Customer name: ' . $fname .  "'n" .  
'Contact-No: ' . $phone .  "'n" . 
'E-mail: ' . $e_mail .  "'n" .
'Service-Type: ' . $service .  "'n" .  
'Car-Make: '. $maker .  "'n" . 
'Car-Model: ' . $model .  "'n" . 
'Model-Year: ' . $year .  "'n" . 
'Service Required: ' . $message .  "'n" ;
$thankyou = "thankyou.html"; // thank you page
if(isset($_POST['fname']) && isset($_POST['phone']) && isset($_POST['e_mail']) && isset($_POST['service']) && isset($_POST['message']))
$maker = $model = $year = 'Not Set'; // Or just use a empty string: '';
if(isset($_POST['maker'])){
    $maker = $_POST['maker'];
}
if(isset($_POST['model'])){
    $model = $_POST['model'];
}
if(isset($_POST['year'])){
    $year = $_POST['year'];
}{
    $fname = $_POST['fname'];
    $phone = $_POST['phone'];
    $e_mail = $_POST['e_mail'];
    $type = $_POST['service'];
    $maker = $_POST['maker'];
    $model = $_POST['model'];
    $year = $_POST['year'];
    $message = $_POST['message'];
    if(empty($phone)){
        echo 'Fields With * Sign Are Mandatory';
    }
    else{
        if(mail($to,$headers,$subject,$body,$headers)){
     header("Location: $thankyou");
?>
<script>location.replace('<?php echo $thankyou;?>')</script>
<?
        }
        else{
            echo 'There was an error sending email/s.';
        }
    }
}

?>

我等你的答案。如果你想知道什么,请告诉我。

查看mail函数。然后,将邮件代码更改为:

mail($to,$subject,$body,$headers)

如果你仍然收不到邮件,这很可能是windows的问题,有很多方法可以解决,但很容易找到。^ ^

就用这个,不需要<script>

if(mail($to,$subject,$body,$headers)){
    header("Location: $thankyou");
}