我被建议在我的php代码中添加标题,因为我的电子邮件通过空白/空表单字段进入我的收件箱,即使用户在点击提交之前已经在网页上输入了它们。如果有人能告诉我我是否做得对,我将非常感激。
<?php
$EmailFrom = "Quote@mydomian.co.uk";
$EmailTo = "me@mydomian.co.uk";
$Subject = "Online contact form";
$fullName = Trim(stripslashes($_POST['fullName']));
$contactNo = Trim(stripslashes($_POST['contactNo']));
$message = Trim(stripslashes($_POST['message']));
// prepare email body text
$Body = "";
$Body .= "fullName: ";
$Body .= $fullName;
$Body .= "\n";
$Body .= "contactNo: ";
$Body .= $contactNo;
$Body .= "\n";
$Body .= "message: ";
$Body .= $message;
$Body .= "\n";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$success = mail($EmailTo, $Subject, $Body, $headers, $EmailFrom");
// redirect to success page
if ($success){
print "<meta http-equiv=\"refresh\" content=\"0;URL=Thankyou.html\">";
}
else{
print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}
?>
答案 0 :(得分:0)
你应该使用php header()函数:
header('Content-type:application / html');
因为这将首先发送到浏览器...
答案 1 :(得分:0)
以下是如何在电子邮件中设置/ sender / reply-headers标头的示例:
$headers = array(
'From: sender name <senderemail@example.com>',
'Sender: senderemail@example.com',
'To: '.$to,
'Reply-To: senderemail@example.com',
'MIME-Version: 1.0',
'Content-Type: text/html; charset=utf-8',
'Content-Transfer-Encoding: 8bit',
);
if ($cc)
$headers[] = 'CC: ' . $cc;
if ($bcc)
$headers[] = 'BCC: ' . $bcc;
$response = @mail($to, $subject, $content, implode("\n", $headers), '-f senderemail@example.com');
注意:如您所见,发件人的电子邮件地址有很多重复,但我注意到邮件客户端和邮件发件人(如sendmail)的行为有所不同,因此需要处理可能的配置