Hooch Posted October 23, 2008 Share Posted October 23, 2008 Is it possible to have a link in an email (being sent from a webpage on my site) with the option to download (and not to view)? I have the email working great, but when you click the link it pops up a new browser and shows the file. I would like to have the link ask if you want to download instead. FYI here is my code //send the email //Set up info $_SESSION['filetoupload'] = $_POST['filetoupload']; $_SESSION['all_emails'] = $_POST['all_emails']; $file_name = $_SESSION['file_name']; $to = "[email protected]"; $subject = stripslashes($_POST['txtSubject']); $message = stripslashes($_POST['txtMessage']); $message .= "<br />"; if($_SESSION['filetoupload'] == 1) { $message .= "<br />"; $message .= "To view file please click the link below."; $message .= "<br /><br />"; $message .= '<a href="http://www.mysite.org/files/emails/'.$file_name.'">'.$file_name.'</a>'; $message .= "<br /><br />"; } $message .= "--------------------"; $message .= "<br /> mysite.org <br />"; $headers = "From: mysite.org\r\n"; $headers .= "Return-Path: <".$to.">\r\n"; $headers .= "MIME-Version: 1.0\r\n"; $headers .= "Bcc:".$_SESSION['all_emails']."\r\n"; $headers .= "Content-Type: text/HTML; charset=ISO-8859-1\r\n"; if(mail($to, $subject, nl2br($message), $headers)) { echo '<b>Mail Sent</b>'; } else { echo '<b>Mail not sent</b>'; } Link to comment https://forums.phpfreaks.com/topic/129788-solved-download-link-in-email/ Share on other sites More sharing options...
trq Posted October 23, 2008 Share Posted October 23, 2008 Take a look here. Link to comment https://forums.phpfreaks.com/topic/129788-solved-download-link-in-email/#findComment-672857 Share on other sites More sharing options...
Hooch Posted October 23, 2008 Author Share Posted October 23, 2008 Great post thank you!! Going to be a challenge to add this the the email script. Link to comment https://forums.phpfreaks.com/topic/129788-solved-download-link-in-email/#findComment-672859 Share on other sites More sharing options...
Hooch Posted October 23, 2008 Author Share Posted October 23, 2008 I have implemented the download script. I changed $message .= '<a href="http://www.mysite.org/files/emails/'.$file_name.'">'.$file_name.'</a>'; to $message .= '<a href="http://www.mysite.org/files/emails/file.php?file='.$file_name.'">Download</a>'; Then I needed to create a file called file.php in the folder where the file is. Here is file.php <?php // force to download a file // ex, ( [url=http://localhost/php/download.php?file=C:/Apache]http://localhost/php/download.php?file=C:/Apache[/url] Group/Apache2/hongkong.php ) // hope this can save your time :-) $file = $_GET['file']; header("Pragma: public"); header("Expires: 0"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Content-Type: application/force-download"); header( "Content-Disposition: attachment; filename=".basename($file)); header( "Content-Description: File Transfer"); //Inform the browser of what's coming -- allowing it properly report download progress and estimated completion time header('Accept-Ranges: bytes'); header('Content-Length: ' . filesize($file)); @readfile($file); ?> Thank you thorpe Link to comment https://forums.phpfreaks.com/topic/129788-solved-download-link-in-email/#findComment-672867 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.