Jump to content

ERROR with mail()


TottoBennington

Recommended Posts

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 = ilovelinkinpark@live.com.ar 

ilovelinkinpark@live.com.ar is my email

 

 

Link to comment
Share on other sites

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 me@mydomain.com

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.