PDA

View Full Version : php mail() - driving me crazy!



krislaib
12-28-2006, 03:00 PM
I've searched this forum, as well as google, and tried many of the examples, but I can't for the life of me get mail() to work.

Here's the current code I'm trying, please let me know what I'm missing:

<?php

echo "Prepare to send...";

$to = "myaddy@gmail.com";
$subject = "Test mail";
$message = "Hello! This is a simple email message.";
$from = "admin@myBHdomain.com";

$headers = "From: $from";

mail($to,$subject,$message,$headers);

echo "Mail Sent.";

?>

When I hit the page, I get the "prepare to send..." text after what seems like a 1 minute timeout. The mail message is never sent, and I don't receive the "Mail Sent" echo to the screen.

Thanks in advance for any help!
-Kris

areidmtm
12-28-2006, 03:12 PM
does admin@myBHdomain.com actually exist?

krislaib
12-28-2006, 03:33 PM
does admin@myBHdomain.com actually exist?

Yes it does. I created it via the BlueHost ControlPanel | email manager | list/add/remove POP email accounts, which I assume is the correct place?

areidmtm
12-28-2006, 05:37 PM
try using this as your header



$headers = 'From: admin@domain.com' . '\r\n' .
'Reply-To: admin@domain.com' . '\r\n' .
'X-Mailer: PHP/' . phpversion();

krislaib
12-29-2006, 09:12 AM
It didn't work last night after making the headers change, but it does this morning!

I know they've been having issues with the server that my domain is on, so it may be related (although yesterday tech support said it wasn't).

Either way, Thanks for the help!
-Kris

mu-harry
01-01-2007, 12:26 PM
Check out http://phpmailer.sourceforge.net

I was never able to get the mail() function to work the way I wanted it to, but I discovered that PHPmailer works great and has tons of available options, such as HTML encoded emails, cc, bcc, among others.