Page 1 of 1

form to mail

Posted: Sun Aug 24, 2008 4:17 am
by gilyotina
hi,

i copied a code for form-to-mail. It works, i get the information to my mail box,
but when the user clicks the submit btn the browser opens the php file (just an empty page shows).

why does it open the file and how can i change this behavior?
here's my php file:

Code: Select all

<!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=utf-8" />
<title>Untitled Document</title>
</head>
 
<body>
 
<script language="php">
$email = $HTTP_POST_VARS[email];
$mailto = "mymail@gmail.com";
$mailsubj = "Form submission";
$mailhead = "From: $email\n";
reset ($HTTP_POST_VARS);
$mailbody = "Values submitted from web site form:\n";
while (list ($key, $val) = each ($HTTP_POST_VARS)) { $mailbody .= "$key : $val\n"; }
if (!eregi("\n",$HTTP_POST_VARS[email])) { mail($mailto, $mailsubj, $mailbody, $mailhead); }
</script>
 
</body>
</html>
 
I understand nothing about php. Could be a silly mistake.
Here's the html:

Code: Select all

<fieldset id="registerform">
<legend>Get our newsletter</legend>
<form method="post" action="register.php">
Email<br />
<input type="text" name="email" id="formemailbox">
<input type="submit" value="ok">
</form>
</fieldset>
Any ideas?

Re: form to mail

Posted: Sun Aug 24, 2008 9:30 am
by jaoudestudios
Your php mail function is not protected against header injections. You will get your IP block and potentially bring your mail server down.
Use this class instead, as it protects against header injection (spam)...there is an example at the top
http://www.forum.jaoudestudios.com/view ... ?f=13&t=13

Re: form to mail

Posted: Sun Aug 24, 2008 9:50 am
by coder500
When u press submit button register.php opens. It doesn't contain anything to display. It contains only the script to send mail.