Jump to content


SMTP problem


8 replies to this topic

#1 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 03 October 2006 - 02:52 PM

hi P2L!!! i have a little problem, i'm doing a login system for my web page and i want to send e-mail to everybody who register or changes password. the problem i have is that the e-mail does not get send because of a port problem or somethinf like that, it reads like this:

Warning: mail() [function.mail]: Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\Archivos de programa\xampp\htdocs\mailer.php on line 58

Warning: Cannot modify header information - headers already sent by (output started at C:\Archivos de programa\xampp\htdocs\mailer.php:58) in C:\Archivos de programa\xampp\htdocs\process.php on line 169

the mailer.php file contains both mails the one it is send when you register and the one it is send when you change your password.
and goes like this:

<? 
/**
 * Mailer.php
 *
 * The Mailer class is meant to simplify the task of sending
 * emails to users. Note: this email system will not work
 * if your server is not setup to send mail.
 *
 * 
 *
 */
 
class Mailer
{
   /**
	* sendWelcome - Sends a welcome message to the newly
	* registered user, also supplying the username and
	* password.
	*/
   function sendWelcome($user, $email, $pass){
	  $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
	  $subject = "my site - Welcome!";
	  $body = $user.",\n\n"
			 ."Welcome! You've just registered at my Site "
			 ."with the following information:\n\n"
			 ."Username: ".$user."\n"
			 ."Password: ".$pass."\n\n"
			 ."If you ever lose or forget your password, a new "
			 ."password will be generated for you and sent to this "
			 ."email address, if you would like to change your "
			 ."email address you can do so by going to the "
			 ."My Account page after signing in.\n\n"
			 ."- Atte: me";

	  return mail($email,$subject,$body,$from);
   }
   
   /**
	* sendNewPass - Sends the newly generated password
	* to the user's email address that was specified at
	* sign-up.
	*/
   function sendNewPass($user, $email, $pass){
	  $from = "From: ".EMAIL_FROM_NAME." <".EMAIL_FROM_ADDR.">";
	  $subject = "my site - Your new password";
	  $body = $user.",\n\n"
			 ."We've generated a new password for you at your "
			 ."request, you can use this new password with your "
			 ."username to log in to mysite .\n\n"
			 ."Username: ".$user."\n"
			 ."New Password: ".$pass."\n\n"
			 ."It is recommended that you change your password "
			 ."to something that is easier to remember, which "
			 ."can be done by going to the My Account page "
			 ."after signing in.\n\n"
			 ."- Atte: Me";
			 
	  return mail($email,$subject,$body,$from);
   }
};

/* Initialize mailer object */
$mailer = new Mailer;
 
?>

this is the prosses.php part of the code that get the mail done.

/**
	* procForgotPass - Validates the given username then if
	* everything is fine, a new password is generated and
	* emailed to the address the user gave on sign up.
	*/
   function procForgotPass(){
	  global $database, $session, $mailer, $form;
	  /* Username error checking */
	  $subuser = $_POST['user'];
	  $field = "user";  //Use field name for username
	  if(!$subuser || strlen($subuser = trim($subuser)) == 0){
		 $form->setError($field, "* Username not entered<br>");
	  }
	  else{
		 /* Make sure username is in database */
		 $subuser = stripslashes($subuser);
		 if(strlen($subuser) < 5 || strlen($subuser) > 30 ||
			!eregi("^([0-9a-z])+$", $subuser) ||
			(!$database->usernameTaken($subuser))){
			$form->setError($field, "* Username does not exist<br>");
		 }
	  }
	  
	  /* Errors exist, have user correct them */
	  if($form->num_errors > 0){
		 $_SESSION['value_array'] = $_POST;
		 $_SESSION['error_array'] = $form->getErrorArray();
	  }
	  /* Generate new password and email it to user */
	  else{
		 /* Generate new password */
		 $newpass = $session->generateRandStr(8);
		 
		 /* Get email of user */
		 $usrinf = $database->getUserInfo($subuser);
		 $email  = $usrinf['email'];
		 
		 /* Attempt to send the email with new password */
		 if($mailer->sendNewPass($subuser,$email,$newpass)){
			/* Email sent, update database */
			$database->updateUserField($subuser, "password", md5($newpass));
			$_SESSION['forgotpass'] = true;
		 }
		 /* Email failure, do not change password */
		 else{
			$_SESSION['forgotpass'] = false;
		 }
	  }
	  
	  header("Location: ".$session->referrer);
   }

thanks in advance

#2 Hit3k

    Young Padawan

  • Members
  • Pip
  • 120 posts
  • Gender:Male
  • Location:Australia

Posted 04 October 2006 - 07:31 AM

Its your mail server or hosts problem maybe the havnt set up one

#3 NGPixel

    Senior Programmer

  • P2L Staff
  • PipPipPipPip
  • 1,410 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design : Coding : Animation

Posted 04 October 2006 - 01:49 PM

As Hit3k said, your server is the problem. If PHP can't connect to its own mail server, you should check if exim is installed properly and if it's up.

#4 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 04 October 2006 - 02:51 PM

thanks!!!! i have checked that in the php.ini file and everything is all right. what else can i do?
thanks in advance

#5 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 04 October 2006 - 04:55 PM

hi!!! i have put my smtp on line and working and with the same code i get this error message:

Warning: mail() [function.mail]: SMTP server response: 553 We do not relay non-local mail, sorry. in C:\Archivos de programa\xampp\htdocs\mailer.php on line 58

Warning: Cannot modify header information - headers already sent by (output started at C:\Archivos de programa\xampp\htdocs\mailer.php:58) in C:\Archivos de programa\xampp\htdocs\process.php on line 169

thanks in advance

#6 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 04 October 2006 - 05:19 PM

hi! now i have this problem, i have no error message, but the confirmation mail is not send help please.
thnaks in advanced

#7 NGPixel

    Senior Programmer

  • P2L Staff
  • PipPipPipPip
  • 1,410 posts
  • Gender:Male
  • Location:Montreal, Canada
  • Interests:Web Design : Coding : Animation

Posted 05 October 2006 - 07:05 AM

Be sure your mail relayers accepts mail from root and nobody users which are used by PHP.

#8 Av-

    I Feel Left Out

  • Members
  • PipPipPipPip
  • 1,971 posts
  • Gender:Male
  • Location:10 ft. below sea level

Posted 06 October 2006 - 04:54 PM

xammp wont send emails for some reason on localhost, put your site online and try again

#9 pukirocks

    Young Padawan

  • Members
  • Pip
  • 75 posts
  • Gender:Male

Posted 06 October 2006 - 04:56 PM

thnaks!!!! it worked like a charm





1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users