mail-form php

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Yvonne

    mail-form php

    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:

    contact.html
    <html>
    <head>
    <title>Kontak t</title>
    <link rel="stylesheet " href="../css/style.css">

    </head>
    <body>
    <h1>Kontakt</h1>
    <h2>Kontakt</h2>
    <form method="post" action="send.ph p">
    Namn:<br><input name="name" type="text" size="30"><br>< br>
    Email:<br><inpu t 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"
    rows="6"></textarea><br><b r>
    <input type="reset" value="Reset">& nbsp;<input type="submit"
    value="Send">
    </form>
    </body>
    </html>

    send.php
    <html>
    <head>
    <title>Kontak ta oss</title>
    <link rel="stylesheet " href="../css/style.css">

    </head>
    <body>

    <?php
    $to = "clownen2005@te lia.com"; //
    $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>";
    }
    elseif(!ereg("^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$",
    $email)) {
    print " <h3>Din email är felaktig.</h3>";
    } else {
    mail('$to', $sub, $messub, $mesmsg, $mesname, $mesemail);
    print " <h3><center>Tac k ".$name." f&ouml;r att du kontaktar
    oss.</center></h3>";
    }
    ?>
    </body>
    </html>

    Can anyone tell me what I am doing wrong?

    Thanks
    Yvonne
  • Oli Filth

    #2
    Re: mail-form php

    Yvonne wrote:[color=blue]
    > 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.[/color]

    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?

    <SNIP CODE>

    --
    Oli

    Comment

    • Steve

      #3
      Re: mail-form php

      [color=blue]
      > $messub = "Subject: ".$subject."\n" ;
      > $mesmsg .= "Message: ".$msg."\n" ;
      > $mesname .= "Name: ".$name."\n ";
      > $mesemail .= "Email: ".$email."\ n";[/color]
      [color=blue]
      > mail('$to', $sub, $messub, $mesmsg, $mesname, $mesemail);[/color]

      Please read the documentation for the mail() function
      <http://www.php.net/manual/en/function.mail.p hp> 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:$emai l" );

      ---
      Steve

      Comment

      • Tim Van Wassenhove

        #4
        Re: mail-form php

        On 2005-09-14, Yvonne <clownen2005@te lia.com> wrote:[color=blue]
        > 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:[/color]

        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 <http://timvw.madoka.be >

        Comment

        Working...