form to mail

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
gilyotina
Forum Newbie
Posts: 1
Joined: Sun Aug 24, 2008 4:12 am

form to mail

Post 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?
User avatar
jaoudestudios
DevNet Resident
Posts: 1483
Joined: Wed Jun 18, 2008 8:32 am
Location: Surrey

Re: form to mail

Post 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
coder500
Forum Newbie
Posts: 20
Joined: Fri Jul 25, 2008 10:24 am
Location: Singapore

Re: form to mail

Post 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.
Post Reply