Hi Guys,

I have a custom modified version of webloginpe for modx cms (not really important) that creates a user when they make a purchase through paypal.

The problem is paypal keeps sending pdt/ipn to the site, so in my code I check for double ups on accounts then it emails out an error warning. The owner/user ends up with 10 or so emails because of paypal sending back to my pdt address.

I am not big on coding so I cant get my head around how to tell paypal to stop after one attempt.

Any ideas?

My custom code:
Code:
<?php
$web_users = $modx->getFullTableName('web_users');
$web_user_attributes = $modx->getFullTableName('web_user_attributes');
$web_groups = $modx->getFullTableName('web_groups');

$username = $_POST['payer_email'];
$password = GeneratePassword(10);
$cachepwd = time();
$fullname = $_POST['last_name'];
$email = $_POST['payer_email'];
$state =  $_POST['address_state'];
$zip =  $_POST['address_zip'];
$phone =  $_POST['contact_phone'];

	function GeneratePassword($length = 10)
	{
        $allowable_characters = "abcdefghjkmnpqrstuvxyzABCDEFGHJKLMNPQRSTUVWXYZ23456789";
        $ps_len = strlen($allowable_characters);
        mt_srand((double)microtime()*1000000);
        $pass = "";
        for($i = 0; $i < $length; $i++) {
            $pass .= $allowable_characters[mt_rand(0,$ps_len-1)];
        }
        return $pass;
	}

$txn_type = $_POST['txn_type'];

if ($txn_type=='web_accept')
{
		$checkName = $modx->db->query("SELECT * FROM ".$web_users." WHERE `username`='".$username."'");
		$limitz = $modx->recordCount($checkName);
		
		if ($limitz > 0)
		{
		require_once 'manager/includes/controls/class.phpmailer.php';
		$messageTpl = $modx->config['websignupemail_message'];
		$myEmail = $modx->config['emailsender'];
		$emailSubject = "Error Same email in use";
		$siteName = $modx->config['site_name'];
		$siteURL = $modx->config['site_url'];
		
		$message = str_replace('[+uid+]', $username, $messageTpl);
		$message = str_replace('[+pwd+]', $password, $message);
		$message = str_replace('[+ufn+]', $fullname, $message);
		$message = str_replace('[+sname+]', $siteName, $message);
		$message = str_replace('[+semail+]', $myEmail, $message);
		$message = str_replace('[+surl+]', $siteURL, $message);
		foreach ($_POST as $name => $value)
		{
			$toReplace = '[+post.'.$name.'+]';
			$message = str_replace($toReplace, $value, $message);
		}

		// Bring in php mailer!
		$Register = new PHPMailer();
		$Register->CharSet = $modx->config['modx_charset'];
		$Register->From = $email;
		$Register->FromName = $siteName;
		$Register->Subject = $emailSubject;
		$Register->Body = $username;
		$Register->AddAddress($myEmail, $fullname);
		
		if (!$Register->Send())
		{
			//stuff
		}
		}

$newUser = "INSERT INTO ".$web_users." (`username`, `password`, `cachepwd`) VALUES ('".$username."', '".md5($password)."', '".$cachepwd."')";
$createNewUser = $modx->db->query($newUser);

$key = $modx->db->getInsertId();
$NewUser['internalKey'] = $key;

$newUserAttr = "INSERT INTO ".$web_user_attributes.
" (internalKey, fullname, email, phone, mobilephone, dob, gender, country, state, zip, fax, photo, comment) VALUES".

" ('".$key."', '".$fullname."', '".$email."', '".$phone."', '".$mobilephone."', '".$dob."', '".$gender."', '".$country."', '".$state."', '".$zip."', '".$fax."', '".$photo."', '".$comment."')";
$insertUserAttr = $modx->db->query($newUserAttr);

$webGroupId = 1;
$modx->db->query("REPLACE INTO ".$web_groups." (`webgroup`, `webuser`) VALUES ('".$webGroupId."', '".$key."')");

require_once 'manager/includes/controls/class.phpmailer.php';
$messageTpl = $modx->config['websignupemail_message'];
		$myEmail = $modx->config['emailsender'];
		$emailSubject = $modx->config['emailsubject'];
		$siteName = $modx->config['site_name'];
		$siteURL = $modx->config['site_url'];
		
		$message = str_replace('[+uid+]', $username, $messageTpl);
		$message = str_replace('[+pwd+]', $password, $message);
		$message = str_replace('[+ufn+]', $fullname, $message);
		$message = str_replace('[+sname+]', $siteName, $message);
		$message = str_replace('[+semail+]', $myEmail, $message);
		$message = str_replace('[+surl+]', $siteURL, $message);
		foreach ($_POST as $name => $value)
		{
			$toReplace = '[+post.'.$name.'+]';
			$message = str_replace($toReplace, $value, $message);
		}

		// Bring in php mailer!
		$Register = new PHPMailer();
		$Register->CharSet = $modx->config['modx_charset'];
		$Register->From = $myEmail;
		$Register->FromName = $siteName;
		$Register->Subject = $emailSubject;
		$Register->Body = $message;
		$Register->AddAddress($email, $fullname);
		
		if (!$Register->Send())
		{
			//stuff
		}
}

?>