联系表格PHP警告

时间:2017-06-30 11:46:06

标签: php forms email

当有人试图从我网站上的联系表单发送电子邮件时,我收到以下错误: [06-Jun-2017 10:09:04 UTC] PHP警告:无法修改标题信息 - 已经/home/../中已经发送的标题(/home/../mail/contact.php:31开始输出)第34行的mail / contact.php

仅在以下电子邮件中发生这种情况: post@domain.com(使用交换)。联系表单适用于gmail ......?

源代码:

<?php
$name    = $_POST['name'];
$email   = $_POST['email'];
$phone   = $_POST['phone'];
$message = $_POST['message'];

$from    = 'From website';
$headers = "From: post@domain.com\r\n";
$headers .= "Reply-To: post@domain.com\r\n";

if ($_POST['avdeling'] == "avdeling1") {
    $subject = 'To person 1';
    $to      = "Person1@domain.com";
} else if ($_POST['avdeling'] == "avdeling2") {
    $subject = 'To person 2';
    $to      = "Person2@domain.com";
} else if ($_POST['avdeling'] == "avdeling3") {
    $subject = 'To person 3';
    $to      = "Person3@domain.com";
} else if ($_POST['avdeling'] == "avdeling4") {
    $subject = 'To person 4';
    $to      = "Person4@domain.com";
} else{
$subject = 'To post';
$to      = "post@domain.com";
}

$body = "name: $name\n Email: $email\n message:\n $message \n Phone: $phone";
?>

<?php
if (isset($_POST['submit'])) {
    if (mail($to, $subject, $body, $from)) {
        header("Location:domain.com");
    } else {
        echo '<p>Error. Try again!</p>';
    }
}
?>

0 个答案:

没有答案