1

这是我用于表单的 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.';
        }
    }

}


?>

我将等待您的回答。如果您想知道任何事情,请告诉我。提前致谢。

4

2 回答 2

2

只需使用它就不需要<script>

if(mail($to,$subject,$body,$headers)){
    header("Location: $thankyou");
}
于 2013-04-23T10:54:57.860 回答
2

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

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

如果还是收不到邮件,很有可能是在windows的问题,有多种解决方法,但很容易找到。^^

于 2013-04-23T11:01:53.680 回答