Jump to content
xisto Community
Sign in to follow this  
Linneus

Mail() Not Working

Recommended Posts

I'm trying to use the mail() function in a script. But it doesnt work. It keeps returning false.
It's a premade script
The code is:

function SendPassword($userName){global $db,$db_tables;//config.php	// set password for username to a random value	// return the new password or false on failure	$new_password = mt_rand();	$qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'";	$db->db_query($qry);	// send notification email	$from = "From: $from_email\r\n";	$msg = "You or someone pretending to be you has requested that your"  . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n"  . "Your account password has been changed to $new_password\r\n"  . "Please change it next time you log in.\r\n";		if (!mail("$email", "Login information", $msg, $from))	{    echo "ERROR : Unable to send notification email.  Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>";	}}

Share this post


Link to post
Share on other sites

Just a few questions to help me see whats wrong;

Are you sure your host allows the mail function (if not using Xisto)?
When you say return false, do you mean it shows the "Contact admin" self made error or it displays a PHP error?

Also try doing just this;

mail("$email", "Login information", $msg, $from)

See if that returns a PHP error when you try to send it. I'm not sure which part of the mail script isn't working but why is there quotes round the email but not the msg and from?

I'll try helping you once you reply, it's hard for me to test scripts that rely on databases since if the database isn't functioning a code properly, it will return an error and hence the rest will not work and return an error.

Share this post


Link to post
Share on other sites

I have changed to code to:

function SendPassword($userName){global $db,$db_tables;//config.php	// set password for username to a random value	// return the new password or false on failure	$new_password = mt_rand();	$qry = "UPDATE $db_tables[Users] SET password=password('$new_password') WHERE user_name='$userName'";	$db->db_query($qry);	// send notification email	$from = "From: $from_email\r\n";	$msg = "You or someone pretending to be you has requested that your"  . "password be changed for your bookmark account hosted at http://$domain/$subdir\r\n\r\n"  . "Your account password has been changed to $new_password\r\n"  . "Please change it next time you log in.\r\n";		if (!mail($userName, "Login information", $msg, $from))	{    echo "ERROR : Unable to send notification email.  Please contact the <a href=\"mailto:$admin@$domain\">Administrator</a>";	}}

Now it doesnt show it self made error message. But I don't get any mail from it. Anyway all usernames are email-addresses. I've tried to change

if (!mail($userName, "Login information", $msg, $from))

to

if (!mail("linneuscool@hotmail.com", "Login information", $msg, $from))

linneuscool@hotmail.com is my email-address. But it doesnt even work then.

Share this post


Link to post
Share on other sites

Did you try the mail on it's own without any IF statements. I know there are some functions that won't work when nested in an if statement. I really can't see what is wrong. If this is a premade script it should be working... Just to verify, and it may be stating the obvious, but you are sure your host allows the mail command and that you are checking your inbox, including any junkmail filters?

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this  

×
×
  • Create New...

Important Information

Terms of Use | Privacy Policy | Guidelines | We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.