get an email->send a encoded url->download a pdf
10-25-2010, 12:33 PM
|
get an email->send a encoded url->download a pdf
|
Posts: 5
Name: steve
|
Hi,
I would an script to give a free PDF as a gift:
1. get an email on a box on my website (like the newsletter subscriptions)
2. send an email to subscriber, with a confirmation url
3. after confirmation, the user will receive a new email, getting a PDF to download (from my localhost, but encoding the url)
Any idea? . I have mailman installed on my server, but i need a more specific solution.
Thank you for your time,
Steve,
|
|
|
|
10-25-2010, 01:47 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
|
Quote:
Originally Posted by stevemail
Hi,
I would an script to give a free PDF as a gift:
1. get an email on a box on my website (like the newsletter subscriptions)
2. send an email to subscriber, with a confirmation url
3. after confirmation, the user will receive a new email, getting a PDF to download (from my localhost, but encoding the url)
Any idea? . I have mailman installed on my server, but i need a more specific solution.
Thank you for your time,
Steve,
|
PHP Code:
<?php //Configurable Options: $URL = ""; //URL to the script. Example: http://mydomain.com/scripts/downloadpd.php (Enter between the quotes) $dlLink = ""; //The file you want to be downloaded. Example: http://mydomain.com/downloads/awesome.pdf (Enter between the quotes)
if(isset($_GET['key'])) { $filename = "keys.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); if(substr_count($contents,$_GET['key']) == 1) { echo "Your download link <a href='" . $dlLink . "'>Download</a>"; } else { echo "Invalid key"; } } else if(isset($_POST['email'])) { function genRandomString() { $length = 26; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = '';
for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; }
return $string; }
$randKey = genRandomString(); echo $randKey; $fileName="keys.txt"; $file = fopen ($fileName, "a"); fwrite($file, $randKey); fclose ($file); mail($_POST['email'], 'Download your PDF', 'Hello, please visit the following URL to download your PDF ' . $URL . '?key=' . '' . $randKey); echo "Check your inbox for the download link."; } else { ?> <form action="" method="POST"> Email: <input type="text" name="email"><br> <input type="submit"> </form> <?php } ?>
The above script I made should work, I have not implemented security measures.
All you need to do is create a file called keys.txt and chmod it to 777.
As for the URL encoding (Like Uppit does for example, to prevent people giving the direct link) you could copy the file into a directory and give a link to that, then have a cronjob that checks every file the the directory, and if the creation date is more than 48 hours ago, it deletes it.
I could give an example if you want, just ask.
Enjoy 
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.
█ Please login or register to view this content. Registration is FREE
Last edited by Justinwiz; 10-25-2010 at 01:51 PM..
|
|
|
|
10-25-2010, 02:48 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 5
Name: steve
|
Thanks a lot, JustinWiz! I downloaded now, and it runs ok, receiving the link on the customer email. Just a question more; in order to save the email adress, would be great to add it on a raw text file, an email by line... (no SQL inserts). Thanks again! Steve,
|
|
|
|
10-25-2010, 03:09 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
|
Quote:
Originally Posted by stevemail
Thanks a lot, JustinWiz! I downloaded now, and it runs ok, receiving the link on the customer email. Just a question more; in order to save the email adress, would be great to add it on a raw text file, an email by line... (no SQL inserts). Thanks again! Steve,
|
Here is an updated version that adds the email address to a text file too.
PHP Code:
<?php //Configurable Options: $URL = ""; //URL to the script. Example: http://mydomain.com/scripts/downloadpd.php (Enter between the quotes) $dlLink = ""; //The file you want to be downloaded. Example: http://mydomain.com/downloads/awesome.pdf (Enter between the quotes)
if(isset($_GET['key'])) { $filename = "keys.txt"; $handle = fopen($filename, "r"); $contents = fread($handle, filesize($filename)); fclose($handle); if(substr_count($contents,$_GET['key']) == 1) { echo "Your download link <a href='" . $dlLink . "'>Download</a>"; } else { echo "Invalid key"; } } else if(isset($_POST['email'])) { function genRandomString() { $length = 26; $characters = '0123456789abcdefghijklmnopqrstuvwxyz'; $string = '';
for ($p = 0; $p < $length; $p++) { $string .= $characters[mt_rand(0, strlen($characters))]; }
return $string; }
$randKey = genRandomString(); //echo $randKey; //[Debug] This shows the code being generated, currently commentened out. $fileName="keys.txt"; $file = fopen ($fileName, "a"); fwrite($file, $randKey); fclose ($file); $fileNameA="emails.txt"; $fileA = fopen ($fileNameA, "a"); fwrite($fileA, $_POST['email'] . "\n"); fclose ($fileA); mail($_POST['email'], 'Download your PDF', 'Hello, please visit the following URL to download your PDF ' . $URL . '?key=' . '' . $randKey); echo "Check your inbox for the download link."; } else { ?> <form action="" method="POST"> Email: <input type="text" name="email"><br> <input type="submit"> </form> <?php } ?>
Add emails.txt in the same directory and chmod it to 777, it saves the emails line by line.
If you need any more help, just ask me 
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.
█ Please login or register to view this content. Registration is FREE
|
|
|
|
10-25-2010, 03:39 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 5
Name: steve
|
Thanks again. Please, a third (and final question). I would to insert/embed this download.php into the main file, index.php. I've tried using something like this; include("http://path to my template/.../download.php") into index.php. Another way could be to post only the form, but i don't know how. Thanks for all!, STeve.
|
|
|
|
10-25-2010, 08:05 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 58
Name: Justin
Location: /etc/httpd/logs/error_log
|
Quote:
Originally Posted by stevemail
Thanks again. Please, a third (and final question). I would to insert/embed this download.php into the main file, index.php. I've tried using something like this; include("http://path to my template/.../download.php") into index.php. Another way could be to post only the form, but i don't know how. Thanks for all!, STeve.
|
You could embed it with an iframe, this way it'll load separately from the rest of your page and still look like it's part of it, here's an example:
HTML Code:
<iframe src="PATH TO SCRIPT" border="0" scrolling="no" width="350">You browser must support frames!</iframe>
__________________
█ Reliable VPS and Minecraft server hosting at extremely affordable prices.
█ Please login or register to view this content. Registration is FREE
Last edited by Justinwiz; 10-25-2010 at 08:09 PM..
|
|
|
|
10-26-2010, 05:12 AM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 5
Name: Sieger
|
Why not use the ' Infinite Responder' script? It's pre-built, and you can use it to do automatic or manual follow ups in the future.
|
|
|
|
10-27-2010, 12:28 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 5
Name: steve
|
Hi again (i not finish yet...),
Nice and useful script for me. Iframe is a good solution too, and now i'm using to embed it. Just some little questions more:
1. How break lines (\n not...) inside body message into:
mail($_POST['email'], 'Download your PDF', 'Hello, please visit the following URL to download your PDF ' . $URL . '?key=' . '' . $randKey);
echo "Check your inbox for the download link.";
2. In the form action, i would to re-style the classic submit button to #3.
<form action="" method="POST">
Email: <input type="text" name="email"><br>
<input type="submit">
3. I'm using a 2.0 styled 'download' buttons. The idea is to substitute the 'submit' buttom of the form, by this kind of buttons:
<div class="btn"><a href="http://unaidea.org/#"><span class="btn_l">Descarregar en .PDF</span><span class="btn_r"></span></a><a href="http://unaidea.org/#">
<span class="btn_l">Descarregar en .ePUB</span><span class="btn_r"></span></a></div>
4. The final provided link to download (after click on email) returns to a newpage. It's possible to provide this echo to the same iframe?
echo "Your download link <a href='" . $dlLink . "'>Download</a>";
5. Thanks, thanks, thanks. This project is for a website concerned to give a non-profit ebook.
Steve,
Last edited by chrishirst; 10-27-2010 at 03:37 PM..
|
|
|
|
10-27-2010, 12:30 PM
|
Re: get an email->send a encoded url->download a pdf
|
Posts: 5
Name: steve
|
Sorry, first item should say 'how' not 'hot'... Steve,
|
|
|
|
|
« Reply to get an email->send a encoded url->download a pdf
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|