Why Does This Code Not Work?

Discussion in 'PHP' started by gobbly2100, Sep 4, 2007.

  1. #1
    Hey,

    Can someone see if they can work out why this code appears not to be working correctly?

    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    <p>Your Name:<br>
    <input name="name" type="text" />
     </p>
    <p>Your Email:<br>
    <input name="email" type="text" />
     </p>
    <p>Subject:<br>
    <input name="subject" type="text" />
     </p>
    <p>Message:<br>
    <textarea name="message" rows="6"></textarea>
     <br />
    <input type="submit" value="Send" /><input type="hidden" name="do" value="send" /><input type="reset" value="Reset" />
     </p></form>
    <?php
    if($_POST['do']=="send") {
    $recipient="myemail@hotmail.com"; // Set your email here //
    $subject=$_POST['subject'];
    $name=$_POST['name'];
    $email=$_POST['email'];
    $message=$_POST['message'];
    $formsend=mail("$recipient", "$subject", "$message", "From: $name ($email)\r\nReply-to:$email");
    echo("<p>Your message was successfully sent!</p>");
    }
    ?>
    Code (markup):
     
    gobbly2100, Sep 4, 2007 IP
  2. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #2
    what is your problem ?
    mail send or not ?
    test it :
    $formsend=mail($recipient, $subject, $message, "From: $name ($email)\r\nReply-to:$email");
     
    James.Blant, Sep 4, 2007 IP
  3. GolfHos

    GolfHos Member

    Messages:
    44
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    43
    #3
    What exactly isn't working?

    If the problem lies in the form post, maybe try this:
    <form method="post" action="<?=$_SERVER['PHP_SELF']; ?>">
     
    GolfHos, Sep 4, 2007 IP
  4. James.Blant

    James.Blant Active Member

    Messages:
    250
    Likes Received:
    5
    Best Answers:
    0
    Trophy Points:
    60
    #4
    but if the action is empty or feel wirh PHP_SELF . that code should work ! beacuse all codes writed on 1 page ! and empty action is == $-SERVER['PHP_SELF']
     
    James.Blant, Sep 4, 2007 IP
  5. sea otter

    sea otter Peon

    Messages:
    250
    Likes Received:
    23
    Best Answers:
    0
    Trophy Points:
    0
    #5
    GolfHos was right (and posted the solution); you aren't echoing out the "action" value in php.

    Change this:

    
    <form method="post" action="<?php $_SERVER['PHP_SELF']; ?>">
    
    Code (markup):
    To this:

    
    <form method="post" action="<?php [b]echo[/b] $_SERVER['PHP_SELF']; ?>">
    
    Code (markup):
     
    sea otter, Sep 4, 2007 IP
  6. gobbly2100

    gobbly2100 Banned

    Messages:
    906
    Likes Received:
    11
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Thanks!

    Seems to be working just fine now.

    :)
     
    gobbly2100, Sep 4, 2007 IP
  7. Jeewhizz

    Jeewhizz Peon

    Messages:
    7
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #7
    You need to validate your incoming data.

    If i were to set Name to:

    Bob\r\nCc:user1@domain.com,user2@domain.com

    THe email would be sent out to those other addresses too...
     
    Jeewhizz, Sep 6, 2007 IP