ricerocket Posted February 8, 2008 Share Posted February 8, 2008 This is a script I'm using as a registration system, and everything works find accept one little part, the part where it creates the email account through my cPanel. I was just wandering if maybe someone could go through this script and see if there are any errors I might have made. Also I'm creating a new thread because this has nothing to do with any of my other posts, so if you see this thorpe please don't delete it again. Heres the code: <?php // database information $dbhost = '--private--'; $dbuser = '--private--'; $dbpassword = '--private--'; $dbName = '--private--'; // form information $fname = $_POST['fname']; $lname = $_POST['lname']; $staddress = $_POST['staddress']; $apt = $_POST['apt']; $city = $_POST['city']; $country = $_POST['country']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $phone = $_POST['phone']; $mm = $_POST['mm']; $dd = $_POST['dd']; $yyyy = $_POST['yyyy']; $sex = $_POST['sex']; $username = $_POST['username']; $password1 = $_POST['password1']; $password2 = $_POST['password2']; $squestion = $_POST['squestion']; $sanswer = $_POST['sanswer']; $sanswer2 = $_POST['sanswer2']; $altemail = $_POST['altemail']; // additional information /***** Mailbox Quota *****/ $quota = "10"; /**** Welcome Mail to send to email address of user ****/ $from = "registrations@--private--.com"; $subject = "Welcome to --private-- Mail"; $messageprt1 = "<br><br>This is an automatically generated email from --private-- Mail<br><br>There is no need to reply to this email.<br><br>Welcome to your new --private-- Mail email account.<br><br>To access your account on the web go to <a href=\"http://www.--private--.com/members\">http://www.--private--.com/members</a> or click on the Webmail link on the --private-- Mail site.<br><br><b>Username - "; $messageprt2 = "</b><br><b>Password - "; $messageprt3 = "</b><br><br>To access your account using a POP3 or IMAP email client the settings you will need are as below....<br><b>Incoming (POP) Server - mail.--private--.com</b><br><b>Outgoing (SMTP) Server - mail.--private--.com</b><br><b>Username - your full --private--.com email address</b><br><br><br>--private-- Mail<br><a href=\"http://www.--private--.com\">http://www.--private--.com</a></body></html>"; /**** Domain ****/ $domain = "--private--.com"; /**** Password Recover Email ****/ $prfrom = "admin@--private--.com"; $prsubject = "Password Recovery"; $prmessageprt1 = "<html><body>This is an automatically generated email password recover message from --private-- Mail<br><br>There is no need to reply to this email.<br><br>Your requested login details are as below....<br><b>Username: "; $prmessageprt2 = "</b><br><b>Password: "; $prmessageprt3 = "</b><br><br>You can login to --private-- Mail email account from our main site <a href=\"http://www.--private--.com\">Here</a><br><br><br>Xolur Mail<br><a href=\"http://www.--private--.com\">http://www.--private--.com</a></body></html>"; /**** Admin Notification address for new email signup ****/ $adminnotifyaddy = "admin@--private--.com"; /**** Path to skin ****/ // Must have trailing slash $skin_path = "../skins/default/"; /**** CPanel Skin ****/ $cpskin = "--private--"; // run through general checks // make sure user filled in username if ( $username == "" ) { $ermsg = "You must enter a username."; } $dbh = mysql_connect ("$dbhost", "$dbuser", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbName"); // make sure username is available $result = mysql_query("SELECT id FROM useraccounts WHERE username='$username'") or die(mysql_error()); $row = mysql_fetch_array( $result ); $id = $row['id']; if ( $id != "" ) { //echo "Username already taken"; $ermsg = "Username is already taken."; } //Check for no blank fields if ( $fname == "" OR $lname == "" OR $staddress == "" OR $apt == "" OR $city == "" OR $country == "" OR $state == "" OR $zipcode == "" OR $phone == "" OR $mm == "" OR $dd == "" OR $yyyy == "" OR $sex == "" OR $username == "" OR $password1 == "" OR $password2 == "" OR $squestion == "" OR $sanswer == "" OR $sanswer2 == "" OR $altemail == "" ) { $ermsg = "All fields of the registration must be completed."; } function check_email_address($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; } //Validate Alternate Email if (check_email_address($altemail)) { //$ermsg = ""; } else { $ermsg = "Invalid alternate email address."; } // creating the email account if ( $ermsg == "" ) { // required cpanel data define( 'CPEMAIL_DOMAIN', '--private--.com'); // Cpanel domain define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL define( 'CPEMAIL_THEME', '--private--'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes // sensitive cpanel info define( 'CPEMAIL_USER', '--private--'); // Cpanel Username define( 'CPEMAIL_PASS', '--private--'); // Cpanel Password if (isset($_POST['send'])) { $password = $_POST['password1']; $url = 'http'.(CPEMAIL_SSL ? 's' : '').'://'.CPEMAIL_USER.':'.CPEMAIL_PASS.'@'.CPEMAIL_DOMAIN.':'.CPEMAIL_PORT.'/frontend/'.CPEMAIL_THEME.'/mail/doaddpop.html'; $url .= '?email='.$username.'&domain='.CPEMAIL_DOMAIN.'&password='.$password.'"a='.CPEMAIL_QUOTA; // makes an fopen request to the url and returns the content function http_request($url) { ini_set('user_agent','MSIE 4\.0b2;'); // set user agent as IE browser $txt = ''; if ($fp = fopen($url, 'r')) { while( !feof($fp) ) { $txt .= fread( $fp, 2082 ); } fclose($fp); } return $txt; // make the http request to cpanel, this is where the email is created // this is just like the browser making the request, only php does it for the user $txt = http_request( $url ); echo '<hr />'; } //Write to DB $domainip = GetHostByName($REMOTE_ADDR); $date = time(); $timestamp = date("F j, Y, g:i a",$date); $dbh=mysql_connect ("$dbhost", "$dbuser", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbName"); mysql_query("INSERT INTO useraccounts (username, password, activated, altemail, fname, lname, securityquestion, securityanswer, ip, timestamp, quota) VALUES('$username', '$password1', '1', '$altemail', '$fname', '$lname', '$squestion', '$sanswer', '$domainip', '$timestamp', '$quota' ) ") or die(mysql_error()); //Mail to user $to = "<$altemail>\n"; mail($altemail, $subject, '<html><body>Hi '.$fname.$messageprt1.$username.'@'.$domain.$messageprt2.$password1.$messageprt3.'</body></html>', "To: $to" . "From: $from\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"); // Mail to Admin //Mail to admin new account notification $to = "<$adminnotifyaddy>\n"; mail($adminnotifyaddy, 'New '.$domain.' Email Account Created', '<html><body>New email account created at <b>--private-- Mail</b><br><br>Email Address: <b>'.$username.'@'.$domain.'</b><br>Password: <b>'.$password1.'</b><br>Quota: <b>'.$quota.' MB</b><br><br>First Name: <b>'.$fname.'</b><br>Last Name: <b>'.$lname.'</b><br>Security Question: <b>'.$squestion.'</b><br>Security Answer: <b>'.$sanswer.'</b><br><br>Alternate Email: <b>'.$altemail.'</b><br><br>Created :<b>'.$timestamp.'</b><br>IP: <b>'.$domainip.'</b><br></body></html>', "To: $to" . "From: $from\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"); /********************************************/ } $target = "http://www.--private--.com/members/done.php?newemail=$requser&pass=$reqpass&name=$fname"; header("location:$target"); } else { $target = "http://www.--private--.com/members/error.php?ermsg=$ermsg"; header("location:$target"); } ?> Thanks guys Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/ Share on other sites More sharing options...
revraz Posted February 8, 2008 Share Posted February 8, 2008 That's a lot of code to sift through. Why not just post the relevant area instead. Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/#findComment-461710 Share on other sites More sharing options...
ricerocket Posted February 8, 2008 Author Share Posted February 8, 2008 Ok, heres a few sections that relate which might be causeing this problem but I'm just a beginner in php so I don't really know what do do if an error comes up These are the variables: // form information $fname = $_POST['fname']; $lname = $_POST['lname']; $staddress = $_POST['staddress']; $apt = $_POST['apt']; $city = $_POST['city']; $country = $_POST['country']; $state = $_POST['state']; $zipcode = $_POST['zipcode']; $phone = $_POST['phone']; $mm = $_POST['mm']; $dd = $_POST['dd']; $yyyy = $_POST['yyyy']; $sex = $_POST['sex']; $username = $_POST['username']; $password1 = $_POST['password1']; $password2 = $_POST['password2']; $squestion = $_POST['squestion']; $sanswer = $_POST['sanswer']; $sanswer2 = $_POST['sanswer2']; $altemail = $_POST['altemail']; And here is the section that creates the email account, then inserts into database, then emails welcome email, after this it either displays success page or error page other than this every other part of this script works fine: // creating the email account if ( $ermsg == "" ) { // required cpanel data define( 'CPEMAIL_DOMAIN', '--private--.com'); // Cpanel domain define( 'CPEMAIL_SSL', 0); // 0 = no SSL, 1 = Uses SSL define( 'CPEMAIL_PORT', 2082); // usually the port is 2082 withought SSL and 2083 with SSL define( 'CPEMAIL_THEME', '--private--'); // x is the default theme, others include: bluelagoon, x2, xmail, xcontroller, monsoon define( 'CPEMAIL_QUOTA', 10); // email quota in Megabytes // sensitive cpanel info define( 'CPEMAIL_USER', '--private--'); // Cpanel Username define( 'CPEMAIL_PASS', '--private--'); // Cpanel Password if (isset($_POST['send'])) { $password = $_POST['password1']; $url = 'http'.(CPEMAIL_SSL ? 's' : '').'://'.CPEMAIL_USER.':'.CPEMAIL_PASS.'@'.CPEMAIL_DOMAIN.':'.CPEMAIL_PORT.'/frontend/'.CPEMAIL_THEME.'/mail/doaddpop.html'; $url .= '?email='.$username.'&domain='.CPEMAIL_DOMAIN.'&password='.$password.'"a='.CPEMAIL_QUOTA; // makes an fopen request to the url and returns the content function http_request($url) { ini_set('user_agent','MSIE 4\.0b2;'); // set user agent as IE browser $txt = ''; if ($fp = fopen($url, 'r')) { while( !feof($fp) ) { $txt .= fread( $fp, 2082 ); } fclose($fp); } return $txt; // make the http request to cpanel, this is where the email is created // this is just like the browser making the request, only php does it for the user $txt = http_request( $url ); echo '<hr />'; } //Write to DB $domainip = GetHostByName($REMOTE_ADDR); $date = time(); $timestamp = date("F j, Y, g:i a",$date); $dbh=mysql_connect ("$dbhost", "$dbuser", "$dbpassword") or die ('I cannot connect to the database because: ' . mysql_error()); mysql_select_db ("$dbName"); mysql_query("INSERT INTO useraccounts (username, password, activated, altemail, fname, lname, securityquestion, securityanswer, ip, timestamp, quota) VALUES('$username', '$password1', '1', '$altemail', '$fname', '$lname', '$squestion', '$sanswer', '$domainip', '$timestamp', '$quota' ) ") or die(mysql_error()); //Mail to user $to = "<$altemail>\n"; mail($altemail, $subject, '<html><body>Hi '.$fname.$messageprt1.$username.'@'.$domain.$messageprt2.$password1.$messageprt3.'</body></html>', "To: $to" . "From: $from\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"); // Mail to Admin //Mail to admin new account notification $to = "<$adminnotifyaddy>\n"; mail($adminnotifyaddy, 'New '.$domain.' Email Account Created', '<html><body>New email account created at <b>--private-- Mail</b><br><br>Email Address: <b>'.$username.'@'.$domain.'</b><br>Password: <b>'.$password1.'</b><br>Quota: <b>'.$quota.' MB</b><br><br>First Name: <b>'.$fname.'</b><br>Last Name: <b>'.$lname.'</b><br>Security Question: <b>'.$squestion.'</b><br>Security Answer: <b>'.$sanswer.'</b><br><br>Alternate Email: <b>'.$altemail.'</b><br><br>Created :<b>'.$timestamp.'</b><br>IP: <b>'.$domainip.'</b><br></body></html>', "To: $to" . "From: $from\n" . "MIME-Version: 1.0\n" . "Content-type: text/html; charset=iso-8859-1"); /********************************************/ } $target = "http://www.--private--.com/members/done.php?newemail=$requser&pass=$reqpass&name=$fname"; header("location:$target"); } else { $target = "http://www.--private--.com/members/error.php?ermsg=$ermsg"; header("location:$target"); } Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/#findComment-461715 Share on other sites More sharing options...
ricerocket Posted February 9, 2008 Author Share Posted February 9, 2008 I gone through the code again and it must be somewhere in the code section in my last post, if someone could take a look at it... Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/#findComment-462500 Share on other sites More sharing options...
AndyB Posted February 9, 2008 Share Posted February 9, 2008 I'm creating a new thread because this has nothing to do with any of my other posts, so if you see this thorpe please don't delete it again. And exactly what is the problem. Posting reams of code and asking IF there are mistakes is pointless. Does it generate errors? What are they specifically, i.e. what's the error message? Does it not do what you expect? Does it do something unexpected? Exactly what happens or doesn't happen that makes you suspect there are mistakes in your code? Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/#findComment-462604 Share on other sites More sharing options...
ricerocket Posted February 10, 2008 Author Share Posted February 10, 2008 It's working it's just not doing the one part that is necessary. This is a list of what the code is expected to do: 1. Makes checks such as invalid email, no blank fields, etc. and if any of them are invalid it sets a veriable for "ermsg = "what they need to fix" 2. If the "ermsg" is empty then it moves on to the email creation through my cPanel 3. Then it inserts the info into the database for password resetting, username checking, etc. 4. It sends an email message to the new registered email address, and then sends on to me the Admin 5. If no "ermsg" it displays the success page otherwise it displays the error page with the error message given Everthing works accept the email accont creation. I'm just lost right now, and I'm not the best programmer when it comes to php but I'm pretty fluent in html because I'm just a beginner. So like ive been saying if anyone sees and error in my code it would help me out alot. Quote Link to comment https://forums.phpfreaks.com/topic/90053-need-help-finding-problem-somewhere-in-script/#findComment-463075 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.