0

It seem that my mail script and redirect are not working. On submit the page goes blank. I have been looking at it for so long my eye are fall out. A fresh set of eye would help.

<?php 

$name    = isset($_POST['name']) ? $_POST['name'] : '';
$email   = isset($_POST['email']) ? $_POST['email'] : '';
$phone   = isset($_POST['phone']) ? $_POST['phone'] : '';
$subject = isset($_POST['subject']) ? $_POST['subject'] : '';
$message = isset($_POST['message']) ? $_POST['message'] : '';
$mail_status = sendMail($name, $email, $phone,$subject,  $message);

function sendMail($name, $email, $phone, $subject, $message)
{
    // Whitespace pattern, icluding different masking methods
    $whitespace = '~(<CR>|<LF>|0x0A|%0A|0x0D|%0D|\\n|\\r|\s)+~i';
    $name = trim(preg_replace($whitespace, '', $name));
    if (empty($name)) {
        return false;
    }
    $email = trim(preg_replace($whitespace, ' ', $email));
    if (empty($email)) {
        return false;
    }
    $mail_to = 'info@website.com';
    $subject = 'New Contact for My Website from ' . $name;
    $body =  "From: $name\n";
    $body .= "E-mail: $email\n";
    $body .= "Phone: $phone\n";
    $body .= "subject: $subject\n";
    $body .= "Message: $message";
    $headers =  "From: $email\r\n";
    $headers .= "Reply-To: '$email\r\n";
    return mail($mail_to, $subject, $body, $headers);

    header("Location: http://website.com/"); 
    exit;   
}
Nisse Engström
  • 4,555
  • 22
  • 24
  • 38
  • _What_ did you look at so long? Usually the first place to start looking at in such situations is the http servers log file. Because that is where runtime errors are logged to. That actually tells you what is wrong where. – arkascha Jun 12 '15 at 19:13

2 Answers2

1

Your header function is never invoked because you have a return function just before this. Your return function will exit the script (or exit a function if you are in one).

Replace return mail($mail_to, $subject, $body, $headers); with:

 mail($mail_to, $subject, $body, $headers);
Ormoz
  • 2,742
  • 10
  • 31
  • 48
kojow7
  • 7,165
  • 11
  • 60
  • 109
0
if(mail($mail_to, $subject, $body, $headers)):
  header("Location: http://website.com/"); 
endif;
Jakir Hossain
  • 2,283
  • 14
  • 23