Community Forums
Connect with us on LinkedIn
+ Reply to Thread
Results 1 to 12 of 12
  1. #1
    Member
    Join Date
    Oct 2004
    Posts
    5

    Lightbulb create email alias/forwarder with a php-script

    Hello,

    I'm trying to create a script that allows every member on my website to create a emailalias 'on the fly'. I have read on the internet that there exists an aliasfile that contains all the forwarders. I thought it was in 'etc/', but I can't find it anywhere
    Or does anyone knows another why to create that on the fly?

    Thanks,

    Steven vd Braak

  2. #2
    Member
    Join Date
    Feb 2004
    Posts
    329

    Default

    http://squirrelmail.org , has a plugin that allows the creation of an alias for email logins. You'd need to install it as a standalone.

  3. #3
    Member
    Join Date
    Oct 2003
    Posts
    1,020

    Default

    Quote Originally Posted by thrunxje
    I thought it was in 'etc/', but I can't find it anywhere
    /etc/valiases/domain.tld

  4. #4
    Member
    Join Date
    Oct 2004
    Posts
    5

    Default

    I have 9.9.1-RELEASE 47 of Cpanel, and Neomail, Horde and Squirrel are installed. I know how to create an alias but not where the mailserver keeps his information. If I could find that file, I could write a script that adds it. When I go to my FTP I can't find any directory named 'valiases'. Maby I just can't see it with FTP.

    Does anyone know how what the direct acces is to that file from my www or public_html folder? Then I can use fopen to acces and edit that file.

    It's not a problem to just add an alias, but I want to give the members of my site direct acces, so they can create there own alias 'on the fly'. Just through a html form with a php script.

    Thanks already!

    Steven vd Braak

  5. #5
    Member PWSowner's Avatar
    Join Date
    Nov 2001
    Location
    ON, Canada
    Posts
    2,994

    Default

    As SarcNBit said, that file is at /etc/valiases/domain.tld.

    That's from the root of the server, not the root of your account. It's not directly accessible by users, but can be written to with a perl or php script. Just specify in the script that the file is at /etc/valiases/domain.tld.
    Mike
    WHM and cPanel Scripts (join our "Scripts Club")
    D/A Photography

  6. #6
    Member
    Join Date
    Oct 2004
    Posts
    5

    Default

    Oh, now I get it, that's why I can't see it on my FTP
    I'll try it!

  7. #7
    Member
    Join Date
    Oct 2004
    Posts
    5

    Default

    It doesn't work

    This is my script:
    PHP Code:
    <?
        
    if(fopen("/etc/valiases/domain.tld","r")){
            echo 
    "I can read it!";    
        }
    ?>
    This is the location

    Does anyone know what I do wrong?

  8. #8
    Member PWSowner's Avatar
    Join Date
    Nov 2001
    Location
    ON, Canada
    Posts
    2,994

    Default

    Have to change the "domain.tld" to the actual domain URL.
    domain.tld doesn't exist
    Mike
    WHM and cPanel Scripts (join our "Scripts Club")
    D/A Photography

  9. #9
    Member
    Join Date
    Jun 2003
    Posts
    396

    Default Here is a forwarder script I created

    Feel free to use this one:
    I use it on my site:

    Code:
    <?php
    	$username="username";	// change username to suite accoutn
    	$password="password";	// change password to suite account
    	$domain="domainname.com";  // change to domain to use
    	$Host = explode("/",$_SERVER['DOCUMENT_ROOT']);
    	include('../header.html'); // comment if you do not use a header
    	$ok = TRUE;
    ?>
    <!-- email.php | create POP email account | Email Form Area -->
          <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
            <table width="600" border="0" align="center" cellpadding="0" cellspacing="0" summary="login form">
              <tr> 
                <td width="600" valign="top"><fieldset class="login" id="login" title="Login">
                  <legend>Create Forwarder</legend>
                  <?
                if (isset($_POST['submit'])) { // Check if the form has been submitted.
        if (empty($_POST['preferred'])) { // Validate the Email.
            $u = FALSE;
            echo '<p><font color=red><strong>You forgot to enter your preferred E-Mail!</strong></font></p>';
        } else {
            $u = $_POST['preferred'];
        }
        
        if (empty($_POST['forwarder'])) { // Validate the forwarder.
            $p = FALSE;
            echo '<p><font color=red><strong>You forgot to enter a forwarder!</strong></font></p>';
        } else {
            $p = $_POST['forwarder'];
        }
    
        if ($u && $p) { 
    // CREATE THE EMAIL HERE
    
    	$file = fopen ("http://$username:$password@69.93.167.154:2082/frontend/x2/mail/doaddfwd.html?email=$preferred&forward=$forwarder&domain=$domain", "r");
    
    	if (!$file) {
    		$ok = FALSE;
            	echo '<p><font color="red"><strong>Email Already Exists!</strong></font> </p>';        
    	}
    	while (!feof ($file)) {
    		$line = fgets ($file, 1024);
    		if (ereg ("already exists!", $line, $out)) {
    		$ok = FALSE;
            	echo '<p><font color="red"><strong>Email Already Exists</strong></font> </p>';        
    		}
    	}
    	fclose($file);
    	if ($ok) {
    $Host = $_SERVER['HTTP_HOST'];
            echo '<p><strong>E-Mail '. $NewEmail .'@'.$Host.' Created.</strong></p>';        
    	}
                    
        } else { // If everything wasn't OK.
    	echo $u;
            echo '<p><font color="red"><strong>Please try again.</strong></font></p>';        
        }
    
    } // End of SUBMIT conditional. 
    ?>
    <table align="center" border="0" cellspacing="1" cellpadding="0">
    	    <tr> 
    	      <td><font size="-1">Preferred Email Address:&nbsp;<br>
    	      <input onFocus=value='' value="thetest" name="preferred" type="text"> 
    		<? echo $_SERVER['HTTP_HOST']; ?>
    		<font color="red"> >>> &nbsp;</font></font>
    	      </td>
    	      <td><font size="-1">Forward To Email: &nbsp; </font><br>
    	      <input onFocus=value='' name="forwarder" value="email@domainname.com" type="text">
    	      </td>
    	    </tr>
    	    <tr> 
    	      <td colspan="2"> <div align="center"> 
    <hr>
    	        <input name="submit" type="submit" id="signupbtn" value="Create Forwarder">
    	        </div></td>
    	    </tr>
    	  </table>
                  </fieldset></tr>
            </table>
          </form>
    
    <table width="300" border="0" align="center" cellpadding="0" cellspacing="
    0" summary="login form">
              <tr>
                <td width="300" valign="top"><fieldset class="login" id="login" title=
    "Login">
                  <legend>Existing Forwarders </legend>
    <?
    //FORWARD
    if ($_POST['delete']) {
    $ok = TRUE;
    //$Email = explode("@",$_POST['delete']);
    //echo $Email[1];
    //echo $delete;
    $Email = explode(" >>> ",$_POST['delete']);
    
    
    $file = fopen ("http://$username:$password@69.93.167.154:2082/frontend/x2/mail/dodelfwd.html?email=$Email[0]=$Email[1]", "r");
    	if (!$file) {
    		$ok = FALSE;
            	echo '<p><font color="red"><strong>Problem Deleting Email!</strong></font> </p>';        
    	}
    	while (!feof ($file)) {
    		$line = fgets ($file, 1024);
    		if (ereg ("Account Deleted!", $line, $out)) {
    		$ok = FALSE;
            	echo '<p><font color="red"><strong>Email Deleted</strong></font> </p>';        
    		}
    	}
    	fclose($file);
    	if ($ok) {
            echo '<p><strong>E-Mail '. $_POST['delete'] .' Deleted.</strong></p>';    		}
    }
    ?>
    <form name=deletemail method=POST action=<? echo $_SERVER['PHP_SELF']; ?> >
    <table border=0 align=center width=90%><tr><td>
    <select size=5 name=delete>
    <?php 
    // Display a List of the current emails
    $Host = explode("/",$_SERVER['DOCUMENT_ROOT']);
    $HOST = "/".$Host[1]."/".$Host[2];
    $file = "/etc/valiases/".$domain;
    $fp = fopen($file, "r");
      if(!is_resource($fp)) {
    	echo "HI";
        return -1;
      }
      while(!feof($fp)) {
        $line = fgets($fp);
        $fields = explode(":", $line);
    	if (($fields[0]) && ($fields[0] != "*" )){
    	echo "<option>".$fields[0]." >>> ".$fields[1];
    	}
      }
    echo "
    </select>
    <td>
    <input type=submit value='Delete Email'>
    </td>
    </form>
    </tr>
    <td colspan=2>
    <B>NOTE:</B>
    Selecting an email address and then pressing the Delete Email button will delete the account. You will <b>NOT</b> be asked to confirm this process!.
    </td>
    </table>
    </fieldset>
    </td>
    </tr>
    </table>";
    
    
    // Include the HTML footer.
    include('../footer.html');
    ?>
    Modify for your own needs.
    -Albert

  10. #10
    Member
    Join Date
    Oct 2004
    Posts
    5

    Default

    YES!!!
    It works, now I get it....thank you very much!

    Steven vd Braak

  11. #11
    Member
    Join Date
    Feb 2004
    Location
    Chicago
    Posts
    196

    Default

    is this to create a email forwarder? (just to verify)

  12. #12
    cPanel Staff cpanelnick's Avatar
    Join Date
    Feb 2003
    Location
    Houston, TX
    Posts
    4,597

    Default

    Please call /usr/local/cpanel/cpanel-email directly.. its a lot better idea as its api is frozen.

Similar Threads & Tags
Similar threads

  1. php script to create email account is not working
    By ctello in forum cPanel Developers
    Replies: 1
    Last Post: 08-02-2011, 02:03 PM
  2. Email alias/forwarder
    By davejames in forum E-mail Discussions
    Replies: 1
    Last Post: 03-01-2011, 10:05 AM
  3. How to create email domain alias?
    By kornell in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 06-20-2007, 04:02 AM
  4. How could I write a PHP script to create email accounts?
    By N9ne in forum cPanel and WHM Discussions
    Replies: 4
    Last Post: 04-19-2003, 08:30 PM
  5. Script to create email alias
    By iguana in forum cPanel and WHM Discussions
    Replies: 0
    Last Post: 06-22-2002, 05:56 AM
Linkedin       Facebook       Twitter       RSS       Flickr       YouTube