Forum Moderators: phranque
how can i block any outside direct access to the folder conataining the php files and prevent executing the scripts directly but only by the html form using .htaccess?
You will need to add server-side logic to both the caller (contact form) page and the email script. The caller should set something, like a session variable, the email script should check for its existence of this variable.
An another way of overcoming this problem is to restrict the allowed recipient in the email script (the recipients are known), and also make sure the parameters of the email script is not containing email headers and things, the most common mistake people used to make is to add the user specified email address into the headers of the email, but that can be 'hacked' if it is not checked to be a valid email address.
Anyway, you should look into forums like PHP Server Side Scripting [webmasterworld.com] and Website Technology Issues [webmasterworld.com], or search on google for keywords like safe email script or sendmail.php.