Darkmatter5 Posted May 15, 2008 Share Posted May 15, 2008 I have Gallery2 installed on my server and it lets you register a user which emails you a message for verification. I've tried creating a user based website of my own from scratch. I've tried using the following code to test if the mail() function of PHP is working. <?php $to="[i]my email address here[/i]"; $subject="Test mail"; $message="Hello! This is a simple email message."; $from="someonelse@example.com"; $headers="From: $from"; mail($to,$subject,$message,$headers); echo "Mail Sent."; ?> If I run the file, Mail Sent. is displayed, but no email is received. Gallery2 works fine, so either the mail function of php is working, but my code is wrong or Gallery2 uses other means of sending it's email. Any ideas? Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/ Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 First, try this and tell us what happens. <?php $to="[i]my email address here[/i]"; $subject="Test mail"; $message="Hello! This is a simple email message."; $from="someonelse@example.com"; $headers="From: $from"; $bool = mail($to,$subject,$message,$headers); if ($bool) { echo "Mail Sent."; } else { echo "Mail Not Sent."; } ?> mail() returns a boolean. TRUE if the sending was successful and FALSE if not. make sure it's executing successfully. Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542317 Share on other sites More sharing options...
Darkmatter5 Posted May 15, 2008 Author Share Posted May 15, 2008 It replied "Mail Sent." Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542328 Share on other sites More sharing options...
DarkWater Posted May 15, 2008 Share Posted May 15, 2008 Charlieholder, mail() cannot accurately reply with the success of the send, it just returns the success of the function call. if (mail()) does almost nothing. Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542333 Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 @dark: I said it would tell you if it EXECUTED correctly. @op: Is your email address wrapped in those tags? Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542337 Share on other sites More sharing options...
DarkWater Posted May 15, 2008 Share Posted May 15, 2008 "TRUE if the sending was successful and FALSE if not." =P Just clarifying for the original poster, don't get defensive. xD Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542340 Share on other sites More sharing options...
Darkmatter5 Posted May 15, 2008 Author Share Posted May 15, 2008 no that was just me attempting to italicize the "my email address here" text. I ran what you asked and it replies "Mail Sent." Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542350 Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 @darkwater: I'm not getting defensive. I was just trying to clarify too. Too bad you can't read tone from words Maybe I should use more wink faces when I type. @op: So you added the italics after the fact just for the sake of showing in the post? They are not in your code that you're running when trying to send the mail? Does your host allow you to send mail? I heard a crazy story about a hosting company not letting anyone use the mail function. Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542366 Share on other sites More sharing options...
DarkWater Posted May 15, 2008 Share Posted May 15, 2008 There should be <sarcasm></sarcasm> and <disgruntled></disgruntled> tags. That would make things a tad easier. D: Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542371 Share on other sites More sharing options...
Darkmatter5 Posted May 15, 2008 Author Share Posted May 15, 2008 Nope the and are not in the code I'm running. In regards to my host letting me send mail, I'm assuming I can as I have Gallery2 in stalled and it uses a user registration system that sends the user an email for activating their account. Gallery2 is on the same server, and it works for Gallery2, so either my code is wrong or Gallery2 sends mail via other means. Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542391 Share on other sites More sharing options...
soycharliente Posted May 15, 2008 Share Posted May 15, 2008 I just ran the code you supplied on my server and I got the email. I don't really know what to say. Double check the email address. Did you type it in wrong and not realize? Quote Link to comment https://forums.phpfreaks.com/topic/105819-php-mail-finction/#findComment-542402 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.