Web Hosting Vodahost    

Home Take The Royal Tour! Order Now Features Prices
Go Back   Web Hosting > VodaHost Web Hosting Support > Email Problems (POP, SMTP & Webmail)

Notices

Email Problems (POP, SMTP & Webmail) Covers problems with receiving and sending Email, configuring your email services (ie. Outlook, Eudora, Pegasus) and using webmail.

Closed Thread
 
Thread Tools
  #1  
Old 07-10-2008, 10:09 PM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #2  
Old 07-11-2008, 12:11 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 10,052
Default Re: Problem sending email via php script

Why do you need to use smtp authentication ?
And, you have code missing in rtreiving the password from the DB.

Use this:

<?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);
$row = mysql_fetch_array($result, MYSQL_ASSOC);
$Password = $row[Password];
// The above lines of code has been used in my other pages and it works fine
if (mysql_num_rows($result) == 1) {
$mailto = $userId;
$mailsubject = "StudyKitchen Password";
$mailbody = "Your study kitchen password is '$Password' ";
$mailheader = "From: Webmaster-StudyKitchen<webmaster@studykitchen.com>\r\n"
. "MIME-Version: 1.0"."\r\n"
. "Content-Type: text/plain; charset=utf-8"."\r\n"
. "Content-Transfer-Encoding: 8bit"."\r\n"
. "X-Mailer: PHP v".phpversion();
if(!mail($mailto, $mailsubject, $mailbody, $mailheader))
{
echo "<p>Mail not sent for unknown reason </p>";
}
else {
echo"<p>Your password successfully sent!</p>";
}
}
mysql_close($db);
}
?>

Didn't test it, but it should work.
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #3  
Old 07-11-2008, 07:02 AM
Sergeant
 
Join Date: Jun 2008
Posts: 25
Default Re: Problem sending email via php script

General, unfortunately the code did not work. It echoed the statement, "Mail not sent for unknown reason". Could you please take a look at it?

Thanks so much!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #4  
Old 07-11-2008, 07:12 AM
navaldesign's Avatar
General & Forum Moderator
 
Join Date: Oct 2005
Location: Italy
Posts: 10,052
Default Re: Problem sending email via php script

Sorry,

change to

$mailto = $userId;

I also added "From:" that was missing
__________________
Navaldesign
Logger Lite: Low Cost, Customizable, multifeatured Login script
Instant Download Cart: a Powerfull, Customized, in site, DB driven, e-products Cart
DBTechnosystems.com Forms, Databases, Shopping Carts, Instant Download Carts, Loggin Systems and more....
Advanced BlueVoda Form Processor : No coding form processor! Just install and use! Now with built in CAPTCHA!

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
  #5  
Old 07-12-2008, 06:50 AM
Sergeant
 
Join Date: Jun 2008
Posts: 25
Default Re: Problem sending email via php script

Navaldesign,

Hats off to you, Sir!! The code worked. Thank you so much.

Regards
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Closed Thread


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off



All times are GMT +1. The time now is 01:39 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC7
2005-2009 VodaHost Web Hosting Your Perfect Web Host - All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203