SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Looking for script to generate email for free download

    Hi. I want to offer a free ebook on my site and once someone inputs there email address an email will go to them with the download link and I keep the persons email on the database.
    Would anyone know where could I find a script to do this? Much appreciated for any help.

  2. #2
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will the link be exactly the same for each person who registers? If so, then this could be achieved in a very short amount of code.

    Additional email validation (from as little as checking the format, to going as far as to check the address exists at the domain) could add additional lines, but this kind of validation routine is already out there for the taking.

    Alternatively, if the link is only to be used once i.e. if the link is passed to someone else it won't work, then a unique random sequence can be generated and entered into the DB record for that email address.

    The sequence would be passed with the URL which adds a timestamp to the DB record when first used. The code can then be set to allow access to the file via that URL for a set period - say 1 hour. This allows the user to have a couple of tries in case the download fails.

    Do either of these solutions sound like the thing you're looking for?
    From the English nation to a US location.

  3. #3
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    HI. thanks. the URL address will be exactly the same each time. I would like the option to just check the format for email validation. Where would you recommend for this?
    thanks

  4. #4
    SitePoint Addict SRTech's Avatar
    Join Date
    Mar 2005
    Posts
    224
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Will you be storing the email for future use?

    Either way, I am guessing this woud be a breeze for quite a few people here. You may even want to try to learn to do it yourself. It would probably be a great project to learn PHP with.

  5. #5
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I've tested this and it does what I think you're asking for.

    First set up your database table using something like the following:
    Code:
    CREATE TABLE 'emailCollector' (
    'id' int(10) unsigned NOT NULL auto_increment,
    'timestamp' timestamp NOT NULL default CURRENT_TIMESTAMP on update CURRENT_TIMESTAMP,
    'email' varchar(50) default NULL,
    PRIMARY KEY ('id')
    )
    Then fill in the required DB-related fields and save this as a php file on your server:
    PHP Code:
    <?php
    // Prevents the page from being cached
    header('Expires: Mon, 26 Jul 1997 05:00:00 GMT'); 
    header('Cache-Control: no-store, no-cache, must-revalidate'); 
    header('Cache-Control: post-check=0, pre-check=0'FALSE); 
    header('Pragma: no-cache'); 
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
        <title>Get my document</title>
        <style type="text/css">
        <!--
         body{font-family: Arial, Helvetica, sans-serif; font-size: 12px;}
         .OK{color: green;}
         .Oops{color: red; font-weight: bold;}
        //-->
        </style>
    </head>
    <body>
    <?php
        
    // The URL of your document 
        
    $linkURL         'http://www.mydomain.com/myFile.ext';
        
    // Your return email address (suggest using from address if you'd rather not enter this)
        
    $from             'myemail@mydomain.com';
        
    // subject of the mail received by registrant
        
    $subject         'Your link to my document';
        
    // Server settings
        
    $server         'localhost';
        
    $server_username 'your_DB_username';
        
    $server_password 'your_DB_password';
        
    $db             'your_DB_name';
     
        
    // On-screen error messages    
        
    $errVal 0;
        
    $outputMsg[0] = "<span class='OK'>Please enter your email address.</span>";
        
    $outputMsg[1] = "<span class='OK'>Thanks. Please check your email for the link.</span>";
        
    $outputMsg[2] = "<span class='Oops'>Please enter a valid email address.</span>";
        
    // Sets URL of this file
        
    $self             $_SERVER['PHP_SELF'];
        
    // Does what it says on the tin 
        
    function validateEmail($addy){
         
    $errVal = (eregi('^([a-zA-Z0-9_\-\.]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$'$addy)) ? 2;
         return(
    $errVal);
        }
     
        
    // Does what it says on the tin
        
    function sendURL($from,$to,$subject,$linkURL){
         
    $header "From: ".$from."\r\n" .
                    
    "Reply-To: ".$from."\r\n" .
                    
    "X-Mailer: PHP/" phpversion();
         
    $header .= "\r\n\r\n";
         
    $body "Thankyou for your interest in my stuff.";
         
    $body .= "\r\n\r\n";
         
    $body .= "Please visit the following link to download the document: ";
         
    $body .= "\r\n";
         
    $body .= $linkURL;
     
         
    /* Should really make this fail gracefully if SMTP server not found */
         
    mail($to$subject$body$header);
     
        }
     
     
        
    // If form has been submitted    
        
    if(isset($HTTP_POST_VARS['formSubmitted'])){
         
    $addy = (isset($HTTP_POST_VARS['addy'])) ? $HTTP_POST_VARS['addy'] : "";
         
    $errVal validateEmail($addy);
         
    // if email address validates
         
    if($errVal == 1){
            
    mysql_connect($server,$server_username,$server_password) or die ("MySQL says: ".mysql_error());
            
    mysql_select_db($db) or die ("MySQL says: ".mysql_error());
            
    $sql "INSERT INTO emailCollector ( email ) VALUES ( '$addy' )";
            
    $result mysql_query($sql);
            
    // echo $result;
     
            
    sendURL($from,$addy,$subject,$linkURL);
         }
        }
     
        
    // Output on-screen text    
        
    echo($outputMsg[$errVal]);
        if(
    $errVal == 1){exit;}
     
    ?>
        <!-- Display form //-->
        <form action="<?php echo($self); ?>" method="post" id="sendEmail">
         <input name="addy" id="addy" value="<?php echo($HTTP_POST_VARS['addy']); ?>" /> <input type="submit" name="formSubmitted" id="formSubmitted" value="Get link..." /> 
        </form> 
     
    </body>
    </html>
    You can download the php code here if you like: DOWNLOAD

    Caveats:
    You should add some further validation to check for SQL injection attacks and possibly some mechanism to prevent the form being used for spamming e.g. checking for multiple submissions from the same IP or forcing the user to enter characters displayed in a graphic.

    Hope that helps.
    From the English nation to a US location.

  6. #6
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Wow! thanks. Im going to give it a crack.

  7. #7
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Works like a dream! thanks!

  8. #8
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Great!

    By the way, how's that my-own.biz site of yours doing? Is it worth the subscription to Article Press? I've never used anything like AP.


    Andy
    From the English nation to a US location.

  9. #9
    SitePoint Member
    Join Date
    Apr 2005
    Posts
    0
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Andy.
    thanks again! I just started developing my-own.biz . I'm learning as I go. What I'm trying to do is develop a membership site which is why I'm offering free ebook hopefully as an incentive to get them to join later (thus I'm gathering emails). Right now I'm trying to figure out what kind of goodies I can offer members in the member's area. So any good ideas would be appreciated. Right now I don't have much of an idea. I'm almost finished the ebook.
    With article press I'm not sure. I just used http://www.articlebuild.com/ which automatically generated the articles on the site. I'm not sure if I will keep it on. It was very easy to set up.
    Could I ask one more question in regards to the script?
    Would it be difficult to mass email everyone on the database created with that script?. How would that be set up?
    thanks

  10. #10
    American't awestmoreland's Avatar
    Join Date
    Sep 2002
    Location
    Grand Rapids, MI
    Posts
    1,168
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't think it would be technically difficult to set up a script to mass mail everyone in your list, but before doing that I'd definitely check the policies of your web host to see how they differentiate between mass mailing and spam otherwise you may find yourself blacklisted.

    If you're not talking about a huge number, then it be initially preferable to export the emails from the database and BCC all of them from your email account. Again, you may run into problems with your ISP if the mail is classed as spam.

    Another alternative is to go with a third party mass mailer such as Graphic Mail. My company sells subscriptions to a rebranded version of Graphic Mail which allows 2000 emails per month for $120 per year.
    From the English nation to a US location.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •