想要通过PHP发送电子邮件并获取感谢页面。但$ HEADER和$ HEADERS没有合作

时间:2013-04-23 10:51:11

标签: php

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

<?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.';
        }
    }

}


?>

我会等你的回答。如果你想知道任何事情,请告诉我。提前谢谢。

2 个答案:

答案 0 :(得分:2)

使用此功能不需要<script>

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

答案 1 :(得分:2)

查看mail功能。然后,将您的邮件代码更改为:

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

如果你仍然没有收到邮件,那很可能是在windows中的问题,它有各种解决方法,但很容易找到。 ^^