Please whitelist cPanel in your adblocker so that you’re able to see our version release promotions, thanks!

The Community Forums

Interact with an entire community of cPanel & WHM users!

CPANEL Mail Script - what am I doing wrong?

Discussion in 'E-mail Discussion' started by mrwhizkid, Oct 25, 2012.

  1. mrwhizkid

    mrwhizkid Registered

    Oct 25, 2012
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator

    The below script works well EXCEPT for it won't check if the email address has already been registered. Could someone take a look and let me know what I'm doing wrong? If I try to register an email that's already been registered, it still shows a success message. Thanks in advance for any help:

     *                             add_email.php
     *                            -------------------
     *   begin                : Thursday, 12 April, 2007
     *   owner                : - Dave
     *   email                :
     *   This program is a free script; you can redistribute it and/or modify
     *   it under the terms of the GNU General Public License as published by
     *   the Free Software Foundation; either version 2 of the License, or
     *   (at your option) any later version.
    include ("includes/config.php");
    // Check that all fields contain a value, if not, return an error.
    $emailcheck = $_POST["email"]; if (preg_match('/[\'\/~`\!@#\$%\^&\*\(\)_\-\+=\{\}\[\]\|;:"\<\>,\.\?\\\]/', $emailcheck)) {echo "<div class=style8>Please go back and remove the special characters from your name.</div>";}
    elseif (!$_POST['password'] | !$_POST['confirm'] | !$_POST['email']) {
    		echo "<div class=style8>Please go back and fill in all of the required fields.</div>";
    elseif ($_POST['password'] != $_POST['confirm']) {
    		echo "<div class=style8>The passwords you entered do not match</div>";
    	function MakeSafe($string){
    		$user  =  strtolower($string);
    		$user  =  stripslashes($string);
    		$user  =  trim($string);
    		$user  =  strip_tags($string);
    		return  $string;
    	$_POST['fname'] = MakeSafe($_POST['fname']);
    	$_POST['lname'] = MakeSafe($_POST['lname']);
    	$_POST['email'] = MakeSafe($_POST['email']);
    	$_POST['password2'] = MakeSafe($_POST['password2']);
    	$_POST['altmail'] = MakeSafe($_POST['altmail']);
    	$domain_name = MakeSafe($domain_name);
    	$cpanel = curl_init();
    	$addr = "http://MYIPADDRESS:2082/frontend/$skin/mail/doaddpop.html";
    	$string_values = "email=$_POST[email]&domain=$domain_name&password=$_POST[confirm]&quota=$email_quota";
    	curl_setopt($cpanel, CURLOPT_URL, $addr);
    	curl_setopt($cpanel, CURLOPT_TIMEOUT, 10);
    	curl_setopt($cpanel, CURLOPT_POST, 1);
    	curl_setopt($cpanel, CURLOPT_USERPWD, "$user:$pass");
    	curl_setopt($cpanel, CURLOPT_RETURNTRANSFER, 1);
    	curl_setopt($cpanel, CURLOPT_POSTFIELDS, $string_values);
    	$cpanel_result = curl_exec($cpanel);
    	curl_close ($cpanel);
    	$start_point = strpos($cpanel_result, 'there'); // Seek Result
    	$end_point = strpos($cpanel_result, 'account.'); 
    	$info = substr($cpanel_result, $start_point, $end_point+8-$start_point);
    	if (preg_match ('/problem/i', "$info")) {
    		print "<br><b><div class=style8>Sorry that account already exists.</b><br><br><a href=javascript:history.go(-1)>Back</a></div>";
    	 }elseif(preg_match ('/You must specify/i', "$info")) {
    		echo "
    		<b><div class=style8>You must specify a password.</b>
    		<br />
    		<br />
    		<a href=javascript:history.go(-1)>Back</a></div>";
    	}else {
    		echo "<div class=style8>Account Successfully Created</div>";
    		echo "<br>
    		<div class=style8>The email account $_POST[email]@$domain_name has now been created, with a quota of <b>$email_quota mb</b>.
    		<br />
    		<b>Username:</b> $_POST[email]@$domain_name <br/>
    		<b>Password:</b> $_POST[confirm]<br /><br />
    		Please use the following link to login to your webmail:<br/> <a href=>Webmail login</a><br />";
  2. Infopro

    Infopro cPanel Sr. Product Evangelist Staff Member

    May 20, 2003
    Likes Received:
    Trophy Points:
    cPanel Access Level:
    Root Administrator
    Why not contact the author of the script listed at the top of it?
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice