How do I implement this idea...

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Tubby
Forum Commoner
Posts: 28
Joined: Thu Oct 17, 2002 5:55 pm

How do I implement this idea...

Post by Tubby »

I have this script which allows people to sign up for an e-mail forwarding account at my domain:

Code: Select all

<?php 
	$pathtoconfig="config.php";
	include("theme.php");
	doheader();
	if(isset($newuser))
	{
		include($pathtoconfig);
		
		$newemail = "$newuser@$domain";
		$mpassword = $password2;
		
		$link = mysql_connect($dbhost, $dbuser, $dbpass);
		mysql_select_db($dbname) or die("Could not select database");
		$query="SELECT username FROM $dbtable WHERE((username = '$newuser'))";
		$result= mysql_query($query,$link);
		if(mysql_num_rows($result) == 0)
			{
				$query="INSERT INTO $dbtable(name,username,password,email) VALUES ('$name','$newuser','$password2','$replymail');";
				mysql_query($query,$link);
				$socket = fsockopen($host,2082);
				$authstr = "$cpaneluser:$cpanelpass";
				$pass = base64_encode($authstr);

    if($emailtype=="mailbox") {

				$in = "GET /frontend/$cpaneltheme/mail/doaddpop.html?email=$newemail&domain=$domain&password=$mpassword&quota=$quota\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n";
				fputs($socket,$in);

                               }

    if($emailtype=="forwarding") {

				$in = "GET /frontend/$cpaneltheme/mail/doaddfwd.html?email=$newuser&domain=$domain&forward=$replymail\r\n HTTP/1.0\r\nAuthorization: Basic $pass \r\n";
				fputs($socket,$in);

                               }

				fclose( $socket );

    if($emailtype=="mailbox") {

				echo "Your account has been setup successfully! Please <a href="index.php">login here</a> to setup your account";
				 
                              }

    if($emailtype=="forwarding") {

				echo "Your e-mail forwarding account has been setup successfully! If you have any questions, feel free to contact us. <a href="index.php">Return to E-Mail Home</a>";

                                 }
			}
		else {
		echo "The username "$newuser" is already in use. Please try another one.<br><a href=signup.php>Back</a>";
		}
		mysql_close($link);
	} 
	
	else { 
include($pathtoconfig);

    if($emailtype=="mailbox") {

echo "<form name="orderform" method="post" action="signup.php"><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="100%" id="AutoNumber1">
<tr>
  <td>
<div align="center">
  <center><br><br><br><br><br><br><br><br><br>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1">
  <tr>
    <td width="50%">Your full Name:</td>
    <td width="50%"><input name="name" type="text" size="20"></td>
  </tr>
  <tr>
    <td width="50%">Other Email Address:</td>
    <td width="50%"><input name="replymail" type="text" size="20">(In case 
    you forget your password)</td>
  </tr>
  <tr>
    <td width="50%">Prefered Email Address:</td>
    <td width="50%"><input name="newuser" type="text" size="20">@$domain</td>
  </tr>
  <tr>
    <td width="50%">Password:</td>
    <td width="50%"><input name="password1" type="password" size="20"></td>
  </tr>
  <tr>
    <td width="50%">Retype Password:</td>
    <td width="50%"><input name="password2" type="password" size="20"></td>
  </tr>
  <tr>
    <td width="50%"> </td>
    <td width="50%"> 
	          <input name="signupbtn" type="button" id="signupbtn" value="Signup" onClick="validateform()" size="20">
    </td>
  </tr>
</table></center>
</div>
 </td>
</tr></table>
	  <script language="JavaScript1.2">
	
	
	function validateform()
	{
		if (checkEmailAddress(document.orderform.replymail))
		{
			if(document.orderform.password1.value == document.orderform.password2.value)
			{
				document.orderform.submit();
			}
			else 
			{
				alert("The passwords you typed do not appear to match");
			}
		}
	}
	
	function checkEmailAddress(field) {
	var good;
	var goodEmail = field.value.match(/\b(^(\S+@).+((\.com)|(\.net)|(\.edu)|(\.mil)|(\.gov)|(\.org)|(\..{2,2}))$)\b/gi);
	
	if (goodEmail){
	   good = true
	} else {
	   alert('Please enter a valid e-mail address.')
	   field.focus()
	   field.select()
	   good = false
	   }
	   return good;
	}
	
	
	</script>
	</form>";

                                 }

 }

    if($emailtype=="forwarding") {

echo "<form name="orderform" method="post" action="signup.php"><table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" width="100%" height="100%" id="AutoNumber1">
<tr>
  <td>
<div align="center">
  <center><br><br><br><br><br><br><br><br><br>
<table border="0" cellpadding="0" cellspacing="0" style="border-collapse: collapse" bordercolor="#111111" id="AutoNumber1">
  <tr>
    <td width="50%">Your full Name:</td>
    <td width="50%"><input name="name" type="text" size="20"></td>
  </tr>
  <tr>
    <td width="50%">E-mail address to forward to:</td>
    <td width="50%"><input name="replymail" type="text" size="20"></td>
  </tr>
  <tr>
    <td width="50%">E-mail address to forward from:</td>
    <td width="50%"><input name="newuser" type="text" size="20">@$domain</td>
  </tr>
  <tr>
    <td width="50%"> </td>
    <td width="50%"> 
	          <input name="signupbtn" type="submit" id="signupbtn" value="Signup" size="20">
    </td>
  </tr>
</table></center>
</div>
 </td>
</tr></table>

	</form>";

                                 }

	 dofooter();
?>
It works correctly and everything, but i have been getting people just filling in any old junk for the forward to address, so I was wondering if it is possible to implement some form of mx records check so that if i sign up and use the e-mail address 'me@something.com' it will come back with something like 'We successfully connected to something.com (216.180.224.178) and confirmed that it's a genuine mail server'

or

i sign up with 'idiot@hotmail.com' it will come back with 'We successfully connected to mx2.hotmail.com (65.54.252.230) and confirmed that it's a genuine mail server.'
then it will continue and create the forwarding account.

But if it encounters and error like the mailbox is full it will come back with 'We were unable to find a way to deliver mail to the address you gave us (idiot@hotmail.com). Please verify that you entered it correctly.
Here's what your MX host said to us when we tried to talk to it:
552 Requested action not taken: exceeded storage allocation '

or if the e-mail address is fake like: lalala@sumpheiosmcdd.com it will come back with 'We were unable to find a way to deliver mail to the address you gave us (lalala@sumpheiosmcdd.com). Please verify that you entered it correctly. Technical: We couldn't find an MX record for your domain.' and then it will stop the signup process and ask you to re-enter your correct e-mail address.

If anyone could implement this for me it would be much appreciated.

note: php n00B (about a month) so a completed script, or step-by-step instructions would be appreciated.

Kind regards,
-Tubby.
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

a common way is to send an activation key to that email-account.
If not used within a specified time (let's say 2 days) the account is decided as invalid and removed.
GroovyinAz
Forum Newbie
Posts: 8
Joined: Tue Oct 01, 2002 6:26 pm
Location: Tucson,AZ

Yes...

Post by GroovyinAz »

or you could use this:

Code: Select all

<?php
$domain = strstr($txtEmail,"@");
if ($domain != "") {
     $domain = substr($domain,1,strlen($domain));
     if (gethostbyname($domain)==$domain) {
          $badfields .= "(EMAIL) That domain is invalid.<BR>";
     }
} else {
    $badfields = $badfields . "Email address not valid.<BR>";
}
?>
The domain is first broken off from the user@ part...
Then, gethostbyname will return the same domain if successful, or false if the domain is not found.

It is still a good idea to send an email with some sort of verification process (ie as mentioned above, the key) to ensure that the person at THAT valid email address was the invididual that registered. And , you have some sort of contact info that's valid should they be up to no good. 8O
good luck.
Post Reply