Okay .. I thought I had this but I guess I don't ... anyone???

Hello all,

I came here a few days ago to get help with my php script and I got what I needed but I ran into another issue that I can’t seem to figure out. When the client enters their email address, the DL activates as expected. But, If you put nothing in the field … it still activates. Now I assumed this was because of the order of the code so I rearranged it, but I can’t seem to get it to work. So here it is before I tried to make the rearrangement:

<?PHP // Define the path to file $file = 'The_gate_vg.pdf'; // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); // Read the file from disk readfile($file); // continue the rest of the php script u want in this dbform.php.. the script that deals with the post data of the form.. $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; if (!isset($_REQUEST['email'])) { header( "Location: http://www.example.com" ); } elseif (empty($email)) { ?>
<html>
<head><title>Error</title></head>
<body>
<h1>Error</h1>
<p>
Oops, it appears you did not enter your
email address correctly. Please press the BACK
button in your browser and try again.
</p>
</body>
</html>

<?php

}
else {
mail( "[email protected]", “This person downloaded the ebook”,
$message, “From: $email” );
}

?>

Anyone that can help my with the correct code placement so I get the result I need?? i.e. - Client enters email … download begins … Client enters email incorrectly … they are redirected to the form.

Thank you SOO Much for any help!!!
Loudvox

I will give you the layout ( order) of the code… you can rearrange based on it.

[php]

<?php $email = $_REQUEST['email'] ; $message = $_REQUEST['message'] ; if (isset($_REQUEST['email'])) { if(!empty($email)) { if(mail( "[email protected]", "This person downloaded the ebook",$message, "From: $email" )) // mail function() returns true if mail is sent properly { // place the heades content for force file download here we are ensuring that, if and only if mail is sent to user, download is started. // Define the path to file $file = 'The_gate_vg.pdf'; // Set headers header("Cache-Control: public"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/zip"); header("Content-Transfer-Encoding: binary"); // Read the file from disk readfile($file); } else { // unable to send mail, might be server problem. } } else { // place the error display content here (if blank email id is submitted } } else header( "Location: http://www.example.com" ); } ?>

[/php]

One more best practice is that, checking the email id empty before submitting the form itself. this can be done using javascript based validation technique.

byraja,

I keep getting sytax errors … Unexpected “}” and “else” . When I try to correct them thinking it was a typo on your part … it kicks back a new syntax error. Can you take a look at your code again please?

Thanks,
Loudvox

change
[php]if (isset($_REQUEST[‘email’]))[/php]
to
[php] if (isset($email)) [/php]

and it should work. i tested with setting email and message and without and both worked fine after the change.

Sorry I added an extra “}” at the end… now i removed it… the following code will work.

[php]
$email = $_REQUEST[‘email’] ;
$message = $_REQUEST[‘message’] ;
if (isset($_REQUEST[‘email’]))
{
if(!empty($email))
{
if(mail( "[email protected]", “This person downloaded the ebook”,$message, “From: $email” )) // mail function() returns true if mail is sent properly
{
// place the headescontent for force file download here we are ensuring that, if and only if mail is sent to user, download is started.

		// Define the path to file 
		$file = 'The_gate_vg.pdf';  
		// Set headers 
		header("Cache-Control: public"); 
		header("Content-Description: File Transfer"); 
		header("Content-Disposition: attachment; filename=$file"); 
		header("Content-Type: application/zip"); 
		header("Content-Transfer-Encoding: binary");    
		
		// Read the file from disk 
		readfile($file);
	}
	else
	{
		// unable to send mail, might be server problem. 
	}
}
else 
{
	// place the error display content here (if blank email id is submitted
}

}
else
header( “Location: http://www.example.com” );

[/php]

Regards,

Sponsor our Newsletter | Privacy Policy | Terms of Service