mail-form php

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi everyone!

I have a problem with php. I guess I am tired because I sure this is  
simple, but I just can't make a simple mailscript work. I have to pages.  
One htm and one php. Here's the code:

<link rel="stylesheet" href="../css/style.css">

    <form method="post" action="send.php">
     Namn:<br><input name="name" type="text" size="30"><br><br>
     Email:<br><input name="email" type="text" size="30"><br><br>
     &Auml;rende:<br><input name="subject" type="text" size="30"><br><br>
     Meddelande:<br><textarea name="msg" cols="25"  
     <input type="reset" value="Reset">&nbsp;<input type="submit"  

     <title>Kontakta oss</title>
<link rel="stylesheet" href="../css/style.css">


$to         = ""; //
$name       = $_POST['name'];
$email      = $_POST['email'];
$subject    = $_POST['subject'];
$msg        = $_POST['msg'];
$sub        = "form to mail";
$messub        = "Subject: ".$subject."\n";
$mesmsg       .= "Message: ".$msg."\n";
$mesname       .= "Name: ".$name."\n";
$mesemail       .= "Email: ".$email."\n";
if(empty($name) || empty($email) || empty($subject) || empty($msg)) {
      echo "   <h3>Du m&aring;ste fylla i alla f&auml;lt.</h3>";
$email)) {
      print "   <h3>Din email är felaktig.</h3>";
} else {
      mail('$to', $sub, $messub, $mesmsg, $mesname, $mesemail);
      print "   <h3><center>Tack ".$name." f&ouml;r att du kontaktar  

Can anyone tell me what I am doing wrong?


Re: mail-form php

Yvonne wrote:
Quoted text here. Click to load it

When posting on a NG, you should really say more than just "I can't
make it work", so we've got something to go on.

Which bit doesn't work? Do you get any error messages? Have you tried
putting in any diagnostics, e.g. echoing the various $_POST fields,
function return values, to see what's going on?



Re: mail-form php

Quoted text here. Click to load it

Please read the documentation for the mail() function
< and don't make up your
own protocol.

Specifically: $to does not need single quotes; the 3rd parameter is
supposed to be the message body, not the subject; the 4th parameter is
extra headers, not the message body; the 5th parameter is usually
unused; the extra headers MUST include a "From:" header; none of the
headers are called "Subject:", "Message:", "Name:" or "Email:".

Try: mail( $to, $sub, $msg, "From:$email" );


Re: mail-form php

Quoted text here. Click to load it

Do you know what happens when (with the headers) someone sends you date with \r\n in where
you don't expect it?

Met vriendelijke groeten,
Tim Van Wassenhove <

Site Timeline