mail() help?

I have a client that I don't host for, who is on a unix server that I know nothing about. I'm trying to set up an email script but it fails and I'm not sure why. I am not a PHP expert. Here's the code I have:

<?php
$to = "[email protected]";
$subject = "Hi!";
$body = "Hi,\n\nHow are you?";
if (mail($to, $subject, $body))
{
echo("<p>Message successfully sent!</p>");
}
else
{
echo("<p>Message delivery failed...</p>");
}
?>

Anybody have any ideas why it always fails?

Thanks for any help!! :)
 
At what point is your script failing? Are you getting any error messages? Are you seeing any messages the script contains upon submitting the form? Post your form here, maybe there is something wrong with it.
 
MetaSkinny, This code doesnt needs a form as it isnt using any variable from the HTTP request.

David, let us know if you see any error. If it is only the email not being delivered, please open a ticket. This can happen if the destination is at providers like AOL,RR or Optimum Online, due to lack of rDNS.

Edit - Your code looks correct.
 
Hi tanmaya

It's actually not on a jodo server. This particular client of mine does not host with me, but just asked for an email form on their site.

There are no error messages received. It simply says "Message delivery failed..." per the script if the mail is not sent. No other message than that, though.

Could it be something in their server configuration?
 
david3rd said:
Could it be something in their server configuration?

It's possible the mail() function is disabled, or PHP not configured to point to an appropriate SMTP server.
 
David,

I took the liberty of assuming that you were trying to send email from a HTML form on a web page, even though your code had no HTTP request, as Tanmaya correctly pointed out.

Does your client want someone to fill out a form on their web site and have the information sent to them via email? If not, what is the routine you are trying to accomplish?

Do you have access to the server .ini?

Check out this page http://us2.php.net/mail
 
You might try adding the following before the call to mail()

ini_set("SMTP", 'mailserver.domain.tld');

where mailserver.domain.tld is your client's SMTP server name.

Tim

PS - see here for more info
 
MetaSkinny: Yes, I will be eventually using a form and can set up the requests no problem when I get to that point. For now, I was simply hardcoding everything to test the mail function.

I do not have access to the server ini, nor is there any chance of gaining access.

skypanther: I tried that with their own mail.domain.com, with their host's mail server's domain - no luck.

I think they just need to move hosting to me so I can whip this puppy out real easy. ;) But they're under contract at this other host, and I wonder if their server is messed up.
 
Back
Top