Jump to content

how to send mail by php


zjp

Recommended Posts

<?php

        if ( $REQUEST_METHOD == "POST" ) {

 
        $realname = strip_tags($realname);
        $email = strip_tags($email);
        $feedback = strip_tags($feedback);

 
        $sendto = "[email protected]";
        $subject = "order request";
        $message = "$realname, $email\n\n$feedback";
          mail($sendto, $subject, $message);

              }
        ?>
    <?php

    if ($REQUEST_METHOD=="POST") {
        echo("<p><b>Thank you for your feedback. The following message was sent:</b></p>\n");
        echo("<blockquote><pre>\n");
        echo("$message");
        echo("</pre></blockquote>");
?>
<meta http-equiv="refresh" content="5">
  <?
    }

    else {
?>
<script language="javascript">
  function DoSubmit ()
  {
    if (document.form.realname.value == "") {
      alert ("You forgot to enter your name.");
      document.form.realname.focus ();
      return "";
    }
    if (document.form.email.value == "") {
      alert ("You forgot to enter your email.");
      document.form.email.focus ();
      return "";
    }

    if (document.form.reedback.value == "") {
      alert ("You forgot to enter your feedback. ");
      document.form.reedback.focus ();
      return "";
    }

    document.form.submit ();
  }
</script>
  <form action="<?php echo("$script_name"); ?>" METHOD="POST" name="form">
  <table cellpadding="4" cellspacing="0" border="0">
    <tr><td><b>Name: </b></td><td><input type="text" name="realname" size="25"></td></tr>
    <tr><td><b>Email:</b></td><td><input type="text" name="email" size="25"></td></tr>
    <tr><td colspan=2><b>Feedback:</b><br />
        <textarea name="feedback" rows="12" cols="45" wrap="physical"></textarea>
    </td></tr>
    <tr><td colspan="2" align="center"><input type="submit" onclick="DoSubmit ()" value="send"></td></tr>
  </table>
  </form>


<?php } ?>


??? ??? ??? ??? ???
This code can't send the mail ,who can tell me where i'm wrong !
Thanks a lot!!!!
Link to comment
https://forums.phpfreaks.com/topic/13819-how-to-send-mail-by-php/
Share on other sites

so...what do you mean by it "can't" send the mail? are you getting an error message of some kind? are you getting your "Thank you for your feedback. The following message was sent:" but it wasn't sent? please provide as much details as possible.

and by the way:
[code]
$realname = strip_tags($realname);
$email = strip_tags($email);
$feedback = strip_tags($feedback);
[/code]
unless register_globals is set to ON in your php.ini this won't work. you need to do this:
[code]
$realname = strip_tags($_POST['realname']);
$email = strip_tags($_POST['email']);
$feedback = strip_tags($_POST['feedback']);
[/code]

and it should be $_SERVER['REQUEST_METHOD'] unless register_globals is set to ON, as well.  but even if it IS set to ON, you shouldn't use your variables as you are using them. you should be using $_POST and $_SERVER for security reasons.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.