DeathStar Posted March 22, 2007 Share Posted March 22, 2007 Hi there. I made a register page that send the user their password but it seems that the email isnt sent! Fixed all the errors and still not.. here is my code: <?php session_start(); print "<html> <head> <title> Register</title> </head> <body bgcolor=black><br />"; require "connect.php"; //code by http://www.phpit.net/category/code/string-regular-expressions/ function valid_email ($email) { // First, we check that there's one @ symbol, and that the lengths are right if (!ereg("^[^@]{1,64}@[^@]{1,255}$", $email)) { // Email invalid because wrong number of characters in one section, or wrong number of @ symbols. return false; } // Split it into sections to make life easier $email_array = explode("@", $email); $local_array = explode(".", $email_array[0]); for ($i = 0; $i < sizeof($local_array); $i++) { if (!ereg( "^(([A-Za-z0-9!#$%&'*+/=?^_`{|}~-][A-Za-z0-9!#$%&'*+/=?^_`{|}~\.-]{0,63})|(\"[^(\\|\")]{0,62}\"))$", $local_array[$i])) { return false; } } if (!ereg("^\[?[0-9\.]+\]?$", $email_array[1])) { // Check if domain is IP. If not, it should be valid domain name $domain_array = explode(".", $email_array[1]); if (sizeof($domain_array) < 2) { return false; // Not enough parts to domain } for ($i = 0; $i < sizeof($domain_array); $i++) { if (!ereg("^(([A-Za-z0-9][A-Za-z0-9-]{0,61}[A-Za-z0-9])|([A-Za-z0-9]+))$", $domain_array[$i])) { return false; } } } return true; } session_start(); print <<<EOF <head> <!-- Begin Main Content --> EOF; $IP = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; if (file_exists('ipbans/' . $IP)) { die("<b><font color=red size=+1>Your IP has been banned, there is no way around this.</font></b></body></html>"); } if ($_POST['username']) { if (!valid_email($_POST['email'])) { die("<font color=#66ff00>Sorry, the email is invalid.</font><br /> ><a href='register.php'>Back</a>"); } if (strlen($_POST['username']) < 4) { die("<font color=#66ff00>Sorry, the username you entered is too short.</font></font><br /> ><a href='register.php'>Back</a>"); } $q2 = mysql_query("SELECT * FROM users WHERE email='{$_POST['email']}'"); if (mysql_num_rows($q2)) { print "<font color=#66ff00>E-Mail already in use. Choose another.</font><br /> ><a href='register.php'>Back</a>"; } else { $IP = ($_SERVER['HTTP_X_FORWARDED_FOR']) ? $_SERVER['HTTP_X_FORWARDED_FOR'] : $_SERVER['REMOTE_ADDR']; /* We ensure that somebody has not signed up from this IP in the last 2 hrs = 2 * 60 * 60 = 7200 secs */ $chk_ip_dup = mysql_query("SELECT * FROM users WHERE ip_signup='{$IP}'"); if (mysql_num_rows($chk_ip_dup)) { die("<b><font color=red size=+1>Naugthy, naughty! Moderator advised!</font></b></body></html>"); } // define possible characters $possible = "0123456789bcdfghjkmnpqrstvwxyz"; // set up a counter $i = 0; // add random characters to $password until $length is reached while ($i < { // pick a random character from the possible ones $char = substr($possible, mt_rand(0, strlen($possible)-1), 1); // we don't want this character if it's already in the password if (!strstr($userpass, $char)) { $password .= $char; $i++; } } $md5password = md5($password); $$usernameconv = $_POST['username']; mysql_query("INSERT INTO `users` (`name` , `password` , `email` , `ip_login` , `ip_signup` , `verified` , `verified_code` ) VALUES ('$username', '$md5password', '$email', '127.0.0.1', '$IP', '0', '$md5password')"); $to = $_POST['email']; $headers = "From: [email protected]"; $subject = "Your new MOGSpam registration"; $email = $_REQUEST['email'] ; $message = "Welcome to MOGSpam!\n\nYour account has been created as follows:\n"; $message = $message . " Login: ".$usernameconv ; $message = $message . " Password: ".$password ; $message = $message . "\n\nIf you did not create this account, please ignore this email. No further action is required"; $message = $message . "\nThis account was registered from IP address ".$IP ; $sent = mail($to, $subject, $message, $headers) ; if($sent) { print "<b>Your Signup was processed sucessfully!!<b><br>"; print "Your password has been sent to ".$_POST['email']."<b><br>"; print "<a href='login.php'>Login</a>"; } else { print "We encountered an error sending your registration email"; } } } else { print "<form action=register.php method=post> <center><table width='75%' class='table' cellspacing='1'> <tr> <td width='30%'><font color=#66ff00>Username</font></td> <td width='40%'><input type=text name=username></td> <td width='30%'></td> </tr> <tr> <td><font color=red>Email</font></td><td><input type=text name=email></td> <td></td> </tr> <tr> <td colspan=3><center><input type=submit value=Submit> </form><br /></td></tr></table></center> <a href='login.php'><font color=red><b>Go Back</b></a></center>"; } print <<<OUT </td> <td class="rgrad"></td> </tr> <tr> <td colspan="3"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tr> <td class="dgradl"> </td> <td class="dgrad"> </td> <td class="dgradr"> </td> </tr> </table> </td> </tr> </table> </center> </body> </html> OUT; ?> Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/ Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 Anyone? Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212969 Share on other sites More sharing options...
UTAlan Posted March 22, 2007 Share Posted March 22, 2007 Try commenting parts of it out to narrow down where the problem may be occurring. Is it messing up in the email validation function? The php mail function? I looked over your code and nothing stuck out to me as incorrect syntax or anything. Try to narrow it down and it should make it easier to find out what's wrong. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212978 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 This si the mail() function: $to = $_POST['email']; $headers = "From: [email protected]"; $subject = "Your new MOGSpam registration"; $email = $_REQUEST['email'] ; $message = "Welcome to MOGSpam!\n\nYour account has been created as follows:\n"; $message = $message . " Login: ".$usernameconv ; $message = $message . " Password: ".$password ; $message = $message . "\n\nIf you did not create this account, please ignore this email. No further action is required"; $message = $message . "\nThis account was registered from IP address ".$IP ; $sent = mail($to, $subject, $message, $headers) ; if($sent) { print "<b>Your Signup was processed sucessfully!!<b><br>"; print "Your password has been sent to ".$_POST['email']."<b><br>"; print "<a href='login.php'>Login</a>"; } else { print "We encountered an error sending your registration email"; } } } cant understand whats worng.. Cant momment anything out or else the script will fail. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212981 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 Can someone give me a mai() function they know work then ill try that? Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212985 Share on other sites More sharing options...
UTAlan Posted March 22, 2007 Share Posted March 22, 2007 From php.net: <?php $to = '[email protected]'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: [email protected]' . "\r\n" . 'Reply-To: [email protected]' . "\r\n" . 'X-Mailer: PHP/' . phpversion(); mail($to, $subject, $message, $headers); ?> Your code looks fine to me, as long as $_POST['email'] is a valid email address. Try substituting that part for a string with an actual email address and see if the code works. Also, what is the purpose of this line: $email = $_REQUEST['email'] ; ? From what I can tell, you never use the $email variable after making that declaration. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212989 Share on other sites More sharing options...
jguy Posted March 22, 2007 Share Posted March 22, 2007 I have noticed that some internet ISP's are killing my mail() function mail as well. Something to do with Spam filters that check header info maybe? I know that some of my mail will go to certain accounts and not to others. All I can think of is anti-spam filters. Anyone else having this behavior? Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212990 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 Dont think ots that case with me though.. On some it could be spam-filters.. but how, I know msn blocks about everything.. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-212999 Share on other sites More sharing options...
Rottingham Posted March 22, 2007 Share Posted March 22, 2007 More than likely it is the spam filters causing your problem. The mail function seems to send, you get a success story, but the email never arrives in the inbox. I have this problem all of the time. Some times more extensive headers allow it to be passed through, sometimes simple headers. It is a real problem, but your web host should be able to check the logs to see what emails were sent or blocked. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-213025 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 and you test it on your own machine? no logs only phpmyadmin and php Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-213042 Share on other sites More sharing options...
ShibSta Posted March 22, 2007 Share Posted March 22, 2007 As far as msn goes for blocking emails, you need to use headers to avoid it. The headers I use are: $html = false; $headers = "MIME-Version: 1.0" . "\r\n"; if($html) { $headers .= "Content-type: text/HTML; charset=ISO-8859-1" . "\r\n"; } else { $headers .= "Content-Type: text/plain; charset=ISO-8859-1" . "\r\n"; } $headers .= "From: \"$from_name\" <" . $from . ">" . "\r\n"; $headers .= "Reply-To: $from" . "\r\n"; $html is a true/false value. If you're sending html messages, define $html as true. $from_name is the name shown instead of the email. (ex. John Doe) $from is the email address which it was sent from. (ex. [email protected]) Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-213046 Share on other sites More sharing options...
DeathStar Posted March 22, 2007 Author Share Posted March 22, 2007 okay.. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-213079 Share on other sites More sharing options...
DeathStar Posted March 23, 2007 Author Share Posted March 23, 2007 There is also a post in this forum somewhere about msn blocking emails.. Link to comment https://forums.phpfreaks.com/topic/43862-solved-simple-yet-complicated/#findComment-213341 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.