i get the following error when someone tries to send e-mail from the contact form on my website: [06-Jun-2017 10:09:04 UTC] PHP Warning: Cannot modify header information - headers already sent by (output started at /home/../mail/contact.php:31) in /home/../mail/contact.php on line 34
This happens only on the following e-mail: post@domain.com (Using exchange). the contact form works fine with gmail... ?
Source code:
<?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>';
}
}
?>