PHP Mail Not Sending Messages

Posted by Kenton de Jong on Stack Overflow See other posts from Stack Overflow or by Kenton de Jong
Published on 2012-12-06T22:43:59Z Indexed on 2012/12/06 23:03 UTC
Read the original article Hit count: 210

Filed under:
|
|

I realize this question title is pretty overused, but I couldn't find an answer to my problem. This could be because either I'm not too good with PHP and I don't understand the problem, or because I have a different issue, but I thought I would post it and see if somebody can help me.

I developed a website for a local church in my city and I made the site on my computer, put it onto my website as a sub directory and tested it all. It worked great. One of the things the client wanted was there to be an email form that can send emails. I made it and all was good.

I then uploaded it onto the church server and thought it went good too. But then we decided to try the email form out, and for some reason it didn't work.

I made the email form by having the user select a recipient (pastor, office manager, etc.) with a radio button, and that would change the action of the email form. I just did something like this:

if (recipent == "pastor") {
    document.forms[0].action = "../scripts/php/pastor_contact.php";
} else if (recipent == "pastoralAssist") {
    document.forms[0].action = "../scripts/php/pastoral_assist_contact.php";    
} else if (recipent == "famMinistry") {
    document.forms[0].action = "../scripts/php/sacra_assist_contact.php";   
} else if (recipent == "sacraAssist") {
    document.forms[0].action = "../scripts/php/fam_ministry_contact.php";   
}

I know this isn't the cleanest, but it works great. The php files then, all look very similar to this (just a different email)"

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$message = $_POST['message'];
$formcontent="From: $name \n Email: $email \n Phone Number: $phone \n Message: $message";
$recipient = "[email protected]";
$subject = $_POST['subject'];
$mailheader = "$subject \r\n";
mail($recipient, $subject, $formcontent, $mailheader) or die("There seems to be an error with this form. Sorry about the inconveince. We are working to get this fixed.");
header('Location: ../../quickylinks/message_sent.html') ;
?>

What this does, briefly, is collect the information from the email form, submit it as an email and then redirect the user to a "Message Sent" page. This works on my server, but not theirs so I believe it's something to do with their server.

You can see their server information here and mine here.

When the user sends the message, they get "There seems to be an error with this form. Sorry about the inconveince. We are working to get this fixed." and the email doesn't go through, although the code is the same on my server and it works fine there.

My initial thought was that PHP wasn't installed on their server (rare, but it does happen). But it was. So then I thought maybe it was installed, but the "mail" function was disabled. So I tried the following php code:

<?php 
if (function_exists('mail')) { 
    echo 'mail() is available'; 
} else { 
    echo 'mail() has been disabled'; }
?>

And it came back with "mail() is available".

So now I'm stuck and I don't know the problem could be. As I said, I'm not very good at PHP yet so if somebody could give a detailed answer, I would be really really thankful!

Thank you so much!

© Stack Overflow or respective owner

Related posts about php

Related posts about webserver