这是我用于表单的 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.';
}
}
}
?>
我将等待您的回答。如果您想知道任何事情,请告诉我。提前致谢。