PDA

View Full Version : Mail



InNeedofHelp
02-25-2006, 08:57 PM
I'm trying to figure out how to use the mail command in PHP, but it won't work for some reason. I have a couple general ideas as to why it doesn't work, but I don't know if any of them are the correct reason. Here are my ideas:

-the mail function doesn't work in PHP 4.1.03 (i think is the version)
-the mail function doesn't work unless run from a server, as in, when testing it on my home computer for developmental purposes, it won't work
-smtp.yahoo.com is malfunctioning
-i'm writing the script wrong

A couple of those could all be the reason, whereas a couple could be completely dumb ideas as to why it doesnt work. But could somebody please help clear this up for me?

Thanks in advance.

Twey
02-25-2006, 09:08 PM
-the mail function doesn't work in PHP 4.1.03 (i think is the version)Should do, as far as I remember.
-the mail function doesn't work unless run from a server, as in, when testing it on my home computer for developmental purposes, it won't workYou're using a remote server (smtp.yahoo.com).
-smtp.yahoo.com is malfunctioningCan you send email? If so, it's not malfunctioning.

Which only leaves:
-i'm writing the script wrong:)

InNeedofHelp
02-25-2006, 09:51 PM
Ah, bummer.

I thought i correctly copied the Mail script right out of the book to see if it'd work.

Could it be that the sendmail_from part of the [Mail] portion is entered incorrectly?
the code looks like this i beleive:

;sendmail_from = myemail@yahoo.com

That semi-colon before the sendmail thing, could that affect the situation?
If not, then I'm all out of options other than I'm writing it wrong :p .

Thanks.

Twey
02-25-2006, 10:17 PM
Well, I guess it just could, being as it causes PHP to completely ignore anything after the semicolon. I guess that could cause a problem, in a few rare cases... :D

InNeedofHelp
02-25-2006, 10:24 PM
Allright, well i'll remove the semicolon there, and then i'll rewrite my script :) .

Thanks, Twey.

InNeedofHelp
02-25-2006, 11:08 PM
One last thing. I'm new to PHP, just started learning it this week. But can you help me find whats wrong with my code?


<html>
<?php
$to = "myemail@yahoo.com";
$subj = "Test";
$message = "This is a mail service test message.";
$mailsend = mail($to,$subj,$message);
if (!$mailsend)
{
echo "Mail not sent.";
}
else
{
echo "Mail sent.";
}
?>
</html>

That is my entire code, and it's supposed to execute the mail function immediately when the page loads, or so I've understood.

But that's my code, is something wrong with it that would cause me to get this outcome: Mail not sent.
Every time i try to run the script?

Twey
02-26-2006, 11:01 AM
it's supposed to execute the mail function immediately when the page loads, or so I've understood.Not quite; it should execute the mail() function when the page is requested. PHP, as a server-side language, doesn't know or care what happens after the page has been sent from the server.

Your firewall could be blocking PHP from connecting to the SMTP server. Try allowing it and seeing what happens. If that fails, write your own simple mail() function using fsockopen (http://www.php.net/fsockopen)() and see where it dies.

InNeedofHelp
02-26-2006, 02:36 PM
So, the mail() function won't execute when my page loads? Do i have to link to the page or something?

Twey
02-26-2006, 05:15 PM
So, the mail() function won't execute when my page loads?No, it executes before your page loads (for the client, that is) :)

InNeedofHelp
02-26-2006, 07:29 PM
Allright, thanks.
So now I just have to make sure I'm coding it correctly and I'm all set.

Thanks, Twey.