TottoBennington Posted January 29, 2012 Share Posted January 29, 2012 This code is to active an account by email, but whei i register any user, this message appears: Warning: mail() [function.mail]: Failed to connect to mailserver at "miniRelay" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in C:\wamp\www\RegisterByEmailActivation\register.php on line 42. <?php include 'global.php'; if (@$_POST['register']) { include 'connect.php'; //get form data $username = addslashes (strip_tags($_POST['username'])); $password = addslashes (strip_tags($_POST['password'])); $email = addslashes (strip_tags($_POST['email'])); if (!$username||!$password||!$email) { echo "Please fill out all the fields!"; } else { //encrypt password $password = md5($password); //check if username already taken $check = mysql_query ("SELECT * FROM users WHERE username ='$username'") or die(mysql_error()); if (mysql_num_rows($check)>=1) { echo "Username already taken"; } else { // generate random code $code = rand (11111111,99999999); // send activation email $to = $email; $subject = "Activate your account"; $body = "Hello $username,\n\nYou registered and need to activate your account, click the link below or paste it into the URL var of your browser\n\n http://localhost/RegisterByEmailActivation/activate.php?code=$code\n\nThanks!"; if (!mail($to, $subject, $body)) { echo"We could not sing up at this time, please try again later!"; } else { //register into database $register = mysql_query("INSERT INTO users VALUES ('','$username','$password','$email','$code','0')"); echo "You have been registered successfully! please check your email ($email) to activate your account"; } } } } ?> <html> <form action='register.php' method='POST'> Choose your username:<br /> <input type='text' name='username'><p /> Choose password:<br /> <input type='password' name='password'><p /> Email:<br /> <input type='text' name='email'><p /> <input type='submit' name='register' value='register'> </form> </html> This is my "php.ini" configuration for mail function: [mail function] ; For Win32 only. ; http://php.net/smtp SMTP = localhost ; http://php.net/smtp-port smtp_port = 25 ; For Win32 only. ; http://php.net/sendmail-from sendmail_from = [email protected] [email protected] is my email Quote Link to comment https://forums.phpfreaks.com/topic/255995-error-with-mail/ Share on other sites More sharing options...
Pikachu2000 Posted January 29, 2012 Share Posted January 29, 2012 Are you sure you're looking at the right .ini file? phpinfo will show you which .ini file is loaded. Quote Link to comment https://forums.phpfreaks.com/topic/255995-error-with-mail/#findComment-1312338 Share on other sites More sharing options...
ocpaul20 Posted January 30, 2012 Share Posted January 30, 2012 Sort out the mail problem first, then place it all together in the program. Write a Mickey-Mouse program with just the mail sending part and run that to debug it. Also something to bear in mind and not necessarily relevant in this case, but has caught me out in the past. Some hosting companies insist you send "From:" an email address at your own domain to avoid spammers using your smtp server. So if you are running a script at mydomain.com, then the from email must be [email protected] Quote Link to comment https://forums.phpfreaks.com/topic/255995-error-with-mail/#findComment-1312508 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.