Jump to content

mail form troubles. Can't see the sender


baudits

Recommended Posts

Hello. Im new to PHP and I have made a mail form for my site. My problem is I can't see the senders e-mail when im receiving an e-mail. Does anyone have an idea what the problem is?

Thanks.

 

The code look like this:

 

 


<form method="post" action="contact.php">
          Enter your Name:<br> <input name="name" type="text"><br>
          E-mail:<br> <input name="email" type="text"><br>
          Subject:<br> <input name="subject" type="text"><br>
          Enter your Message:<br>
          <textarea name="message" rows="15" cols="40"></textarea><br>
          <input type="submit">
      </form>



     <?php
        $to = "[email protected]";
        /*$to = "[email protected]";*/
        $subject = $_REQUEST['subject'];
        $email = $_REQUEST['email'] ;
        $message = $_REQUEST['message'] ;
        $name = $_REQUEST['name'] ;
        $headers = "From: $email";
        if(preg_match( "/[\r\n]/", $name ) || preg_match( "/[\r\n]/", $email))
        {
            print "We encountered an error sending your mail";
        }
        else if (empty($email) || empty($message))
        {
            print "You must enter a message and your E-mail";
        }
        else
        {
            /*$sent = mail($to, $subject, $message, $name, $email) ;*/
            $sent = mail($to, $subject, $message, $name, $headers) ;
            if($sent)
            {
                print "Your mail was sent successfully";
            }
            else
            {
                print "We encountered an error sending your mail 2";
            }
        }
        ?>

 

Link to comment
https://forums.phpfreaks.com/topic/205741-mail-form-troubles-cant-see-the-sender/
Share on other sites

You are using the mail function incorrectly. The format is

<?php
mail($to,$subject,$body,$headers,$extra_headers);
?>

The $extra_headers & $headers variables are optional, but most people use the $headers variable. Read the manual.

 

Ken

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.