views:

79

answers:

4

Hi, I've found several tutorials on how to do this, but it doesn't work. Here's my simple emailing code:

<?php

$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$zone = $_POST['zone'];
$call_time = $_POST['call_time'];
$comment = $_POST['comment'];

$to      = 'MY EMAIL';
$subject = '$name is interested in your product!';
$message = 'name = $name\nemail = $email\nphone = $phone\ntimezone = $zone\nbest time to     call = $call_time\nmessage = $comment';

if(mail($to, $subject, $message))
{
   echo "The information was successfully sent.";
}
else
{
   echo "The information was NOT sent.";
}
?>

(Once I get it working I'll beef up the security)
So any ideas why this isn't working? I get the success message, but not the email.

Ok, so I guess I could have been more specific:

  • I'm running Mac OS X
  • I'm currently testing my site on MAMP (a local Apache, MySQL, and PHP server-thingy :D)
  • Obviously I put a valid email in the "to" field.
  • When I write the errors to a log file, I don't see any

I'm running Mac OS X

A: 

First, you should read the PHP mail page. There are a number of pitfalls.

I would also check to make sure you're actually running an SMTP server on the computer on which you're running the PHP script.

Alex Kaminoff
If he wasn't running an SMTP server, he most probably wouldn't get the success message.
tharkun
That's not true- the function will only return false if the message fails validation or is actively rejected... see the page I linked above.
Alex Kaminoff
+2  A: 

PHP is probably handing off the email to your local smtp server (I think it's postfix) successfully. That will give you your success message. And probably, postfix on your computer is not configured to actually send email out successfully. Or port 25 is blocked by your ISP. Or something else on the email server side.

Your PHP is fine. I think you have a SMTP server configuration issue to work out.

Scott Saunders
You have configure postfix in a way that it forwards or copies all E-Mails to a local account which you then can download with your E-Mail client. Something like test@localhost.
tharkun
A: 

On *nix based systems mail() returning true simply indicates that PHP was able to communicate with sendmail (or one of its substitutes) on your system. True simply indicates it found sendmail where it expected it to, and was able to hand the message off without errors.

The return value is pretty universally useless since: as you've seen it will return true when the mail really won't get anywhere, and under some circumstances it can actually return false and deliver mail successfully.

You've indicated you're on Mac, you may be able to find some error messages by opening up the console. Ultimately you probably don't want your application really sending mail, but configuring your local mail server to serve as a relay should allow it to happen.

preinheimer
A: 

Try using Zend_Mail from Zend Framework, might be easier for you.

StasM