I am trying to use the PHP mail function to allow an email to be sent to a user containing their password once they have entered their email address. I realise the security isn't great as I am passing the password via email but I can focus on that later. For now, I just need the functionality. It seems like the code is working as I get my success message returned, but I receive no email, any ideas? I am using Joomla 3.0 which is hosted on an Apache Server as part of the XAMPP server solution package. I also changed the settings in the global configuration to SMTP as i saw this on other forums but no luck :( I was wondering would the 'localhost' factor be causing a problem?
My code for the form action (after the user has entered their email) is;
<?php
if (isset($_POST['submit']))
{
mysql_connect('localhost','root','') or die("Could not connect to database");
mysql_select_db('joomla_lifestyle') or die("Could not select database");
$email = $_POST['email'];
$sql = mysql_query("SELECT * FROM users WHERE Email ='$email'");
$result = mysql_num_rows($sql);
if ($result == 1)
{
$rows = mysql_fetch_array($sql);
$password = $rows['Password'];
$email = $rows['Email'];
$subject = "Password Request";
$header = "from: ciaraodonovan000@gmail.com";
$body = "Your Password is " . $password;
mail($email, $subject, $header, $body);
$msg = "An Email Containing the Password has been Sent to you!";
header("Location:/Joomla-Lifestyle/index.php?option=com_content&view=article&id=9&msg=$msg");
} else
{
$msg = "User doesn't exist, please try again.";
header("Location:/Joomla-Lifestyle/index.php?option=com_content&view=article&id=9&msg=$msg");
}
}
?>