By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 1,142 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

Warning: mail() [function.mail]: SMTP server response: 503 valid RCPT command must pr

P: 29
Warning: mail() [function.mail]: SMTP server response: 503 valid RCPT command must precede DATA on

whenever user click on to get new password but doesnt fill in the username field it shows that message i have set up the server because if user put username the form works but if left blanck this error message keeps coming up




Expand|Select|Wrap|Line Numbers
  1.  
  2.  function procForgotPass(){
  3.  
  4.       global $database, $session, $mailer, $form;
  5.  
  6.       /* Username error checking */
  7.  
  8.       $subuser = $_POST['user'];
  9.  
  10.       $field = "user";  //Use field name for username
  11.  
  12.       if(!$subuser || strlen($subuser = trim($subuser)) == 0){
  13.  
  14.          $form->setError($field, "* Username not entered<br>");
  15.  
  16.       }
  17.  
  18.       else{
  19.  
  20.          /* Make sure username is in database */
  21.  
  22.          $subuser = stripslashes($subuser);
  23.  
  24.          if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
  25.  
  26.             !eregi("^([0-9a-z])+$", $subuser) ||
  27.  
  28.             (!$database->usernameTaken($subuser))){
  29.  
  30.             $form->setError($field, "* Username does not exist<br>");
  31.  
  32.          }
  33.  
  34.       }
  35.  
  36.  
  37.  
  38.       /* Errors exist, have user correct them */
  39.  
  40.       if($form->num_errors > 0){
  41.  
  42.          $_SESSION['value_array'] = $_POST;
  43.  
  44.          $_SESSION['error_array'] = $form->getErrorArray();
  45.  
  46.       }
  47.  
  48.  
  49.  
  50.  
  51.  
  52.  
  53.  
  54.  
  55.  
  56.       /* Generate new password and email it to user */
  57.  
  58.       else
  59.  
  60.       // make sure seesion starts before
  61.  
  62.       header("Location: ".$session->referrer);
  63.  
  64.  
  65.  
  66.       {
  67.  
  68.          /* Generate new password */
  69.  
  70.          $newpass = $session->generateRandStr(8);
  71.  
  72.  
  73.  
  74.          /* Get email of user */
  75.  
  76.          $usrinf = $database->getUserInfo($subuser);
  77.  
  78.          $email  = $usrinf['email'];
  79.  
  80.  
  81.  
  82.          /* Attempt to send the email with new password */
  83.  
  84.          if($mailer->sendNewPass($subuser,$email,$newpass)){
  85.  
  86.             /* Email sent, update database */
  87.  
  88.             $database->updateUserField($subuser, "password", md5($newpass));
  89.  
  90.             $_SESSION['forgotpass'] = true;
  91.  
  92.          }
  93.  
  94.          /* Email failure, do not change password */
  95.  
  96.          else{
  97.  
  98.             $_SESSION['forgotpass'] = false;
  99.  
  100.          }
  101.  
  102.       }
  103.  
  104.  
  105.  
  106.  
  107.  
  108.    } 


this is my mail set


Expand|Select|Wrap|Line Numbers
  1.  
  2.  function sendNewPass($user, $email, $pass){
  3.  
  4.       $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
  5.  
  6.       $subject = "Elite ticket master - Your new password";
  7.  
  8.       $body = $user.",\n\n"
  9.  
  10.              ."We've generated a new password for you at your "
  11.  
  12.              ."request, you can use this new password with your "
  13.  
  14.              ."username to log in to Eliteticketsevents Site.\n\n"
  15.  
  16.              ."Username: ".$user."\n"
  17.  
  18.              ."New Password: ".$pass."\n\n"
  19.  
  20.              ."It is recommended that you change your password "
  21.  
  22.              ."to something that is easier to remember, which "
  23.  
  24.              ."can be done by going to the My Account page "
  25.  
  26.              ."after signing in.\n\n"
  27.  
  28.              ."- EliteTickets's Site";
  29.  
  30.  
  31.  
  32.  
  33.  
  34.               $server = "smtp.virgin.net";
  35.  
  36.  ini_set("SMTP",$server);
  37.  
  38.  
  39.  
  40.  
  41.  
  42.  
  43.  
  44.        return mail($email,$subject,$body,$from);
Apr 23 '10 #1
Share this Question
Share on Google+
1 Reply


Atli
Expert 5K+
P: 5,058
Hey.

Lines #58 to #66 in your first example. Assuming you meant to have the block starting on line #66 executed on the else condition on line #58, you need to move the header on line #62 inside the block.

IF and ELSE conditions execute ONLY the first line of code directly following them. When this line is the start of a code block, the entire block is executed.

That is, if you have this else clause:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. else
  3. echo "One";
  4.  
  5. {
  6.     echo "Two";
  7.     echo "Three";
  8. }
  9. ?>
The "One" will be printed ONLY if the else clause is triggered, but the "Two" and "Three" will always be executed.

This, on the other hand:
Expand|Select|Wrap|Line Numbers
  1. <?php
  2. else
  3. {
  4.     echo "One";
  5.     echo "Two";
  6.     echo "Three";
  7. }
  8. ?>
Here none of the echoes are executed unless the else clause is triggered.


Also, the sendNewPass function always sends the mail, even if the email is invalid. You should make sure the email is valid before sending the mail, or you risk sending an empty email and running into errors like these.
Apr 23 '10 #2

Post your reply

Sign in to post your reply or Sign up for a free account.