PHP Tutorial: Dynamically Create an Email Address in CPanel

Comment 1 Standard

This assumes you have cPanel and permission to run the /scripts/addpop command. You’ll need to write functions for validateUsername, validatePassword, and usernameExists or you can click on the links for each of those and use mine 🙂

<?php
function createEmail($username, $password)
{
if (!$username || !$password)
   return "Username missing.";
if (!$password)
   return "Password missing.";
if (!validateUsername($username)) //do your validation on the formatting, write this yourself...
  return "Invalid username, please try again.";
if (!validatePassword($password)) //do your validation on the formatting, length & strength, write this yourself...
  return "Invalid password, please try again.";
//check to see if this email address is already taken
if (usernameExists($username)) //write this yourself...
   return "This username already exists. Please select another one.";
//run the command
shell_exec ("/scripts/addpop " .  escapeshellcmd($username) . " " . escapeshellcmd($password))
return "Your email address has been created!";
}
?>
Advertisements

One thought on “PHP Tutorial: Dynamically Create an Email Address in CPanel

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s