View Single Post
  #1  
Old 07-10-2008, 10:09 PM
Skipper02 Skipper02 is offline
Sergeant
 
Join Date: Jun 2008
Posts: 25
Default Sending email via php script

I have written the following lines of code so that if a user forgets his/her password it can be retrieved from the database and mailed to the user at the email that is stored in the database. When I am executing the page I am getting the following error message:

Failed to connect to mail.studykitchen.com:465 [SMTP: Invalid response code received from server (code: -1, response: )]

My code is as follows:

<?php
if (isset($_POST['Email'])) {
$db_host= "localhost";
$db_user = "XXXX_YYYYY";
$db_password = "ZZZZZZ";
$db_name ="XXXX_StudyKitchenData";
$db = mysql_connect($db_host, $db_user, $db_password);
mysql_select_db($db_name, $db);
$userId = $_POST['Email'];
$sql = "SELECT Password FROM UserDetails WHERE Email = '$userId'";
$result = mysql_query($sql, $db);

// The above lines of code has been used in my other pages and it works fine

if (mysql_num_rows($result) == 1) {
require_once "Mail.php";
$from = "Webmaster-StudyKitchen<webmaster@studykitchen.com>";
$to = "'$userId'";
$subject = "StudyKitchen Password";
$body = "Your study kitchen password is '$result' ";
$host = "mail.studykitchen.com";
$port = "465";
$username = "webmaster@studykitchen.com";
$password = "AAAAA";

// I created the above password while creating webmaster mail account. This is not my cp password

$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Your password successfully sent!</p>");
}
}
mysql_close($db);
}
?>

Please help!

I am a VodaHost customer and my domain name is www.studykitchen.com

Thanks