The Community Forums

Interact with an entire community of cPanel & WHM users!
  1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Contact Email added when creating new account

Discussion in 'E-mail Discussions' started by mikelegg, Mar 29, 2005.

  1. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    I'm using PHP to create new customer accounts and I'd like to add the customer's contact email address when the account is created. I know that createacct() doesn't include this parameter and I've found a few posts that provide clues on how to do this, but none that fully explain it. Is someone able to spell this out for me please (I'm a bit thick) :)
     
    #1 mikelegg, Mar 29, 2005
    Last edited: Mar 29, 2005
  2. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    I don't do much php programming, but what you need to do is have the script write the contact email to the file:
    /home/username/.contactemail
     
  3. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    Thanks

    Thanks for that - I'll give it a go. :)
     
  4. mikelegg

    mikelegg Well-Known Member

    Joined:
    Mar 29, 2005
    Messages:
    330
    Likes Received:
    0
    Trophy Points:
    16
    Yes! - This is how you do it!!

    This example assumes that you've already captured the customers details in local variables
    $acctuser,$acctpass, $email etc

    <?php

    // Step 1: Create the account using the createacct() function
    createacct ($host,$user,$accesshash,$usessl,$acctdomain,$acctuser,$acctpass,$acctplan);

    // Step 2: Create a temporary text file on your server
    $objFile = fopen("mytempfolder/contactemail_". $acctuser .".txt", "w+");

    /* NOTE: (i) The mytempfolder will have to have write permissions (ii) You can call the text file anything you want but each one should have a unique name so that if 2 or more customers are signing up at once they don't overwrite each others files. I'm using the $acctuser as part of the file name because in my overall process I've already ensured that it is unique. */

    // Step 3: Write the customers email address into the text file
    fwrite($objFile, $email);

    // Step 4: Save the file
    fclose($objFile);

    /* Now we have to get it to the users folder on the web server - I think the easiest way to do this is to FTP it */

    // Step 5: Set up an ftp connection
    $conn_id = ftp_connect("nnn.nn.nn.nn");
    /* NOTE: You can use the IP Address of the server or an existing domain name, but at this point the customer's domain name probably won't have been delegated so we can't use it. */

    //Step 6: Login with the customers username and password
    $login_result = ftp_login($conn_id, $acctuser, $acctpass);

    // Step 7: Upload the file
    $upload = ftp_put($conn_id, ".contactemail", "mytempfolder/contactemail_". $acctuser .".txt", FTP_BINARY);

    ?>

    Mission Accomplished!

    After this you can clean up the temp file from your server.

    You may also want to add some error handling to the above script as well - this just outlines the basic steps.
     
  5. PWSowner

    PWSowner Well-Known Member

    Joined:
    Nov 10, 2001
    Messages:
    2,948
    Likes Received:
    3
    Trophy Points:
    38
    Location:
    ON, Canada
    Much easier in perl.

    open (datafile, ">/home/username/.contactemail");
    print datafile $email;
    close (datafile);
    system ("chown username:username /home/username/.contactemail");
    system ("chmod 0600 /home/username/.contactemail");

    Easier for me since perl is what I use. ;)
     
Loading...

Share This Page