Hello I have a simple question but it might be late so that might be why I can't figure it out. I have put together just a simple contact form. I have the normal stuff added like email, subject, message, etc. I want to add the name and have it show up in the message but I have forgot how to do this. I have it set up in the html form and made a variable for it but it doesn't work unless I remove the name variable from the php script, otherwise it works great.

Here is the html form.....

<form method="post" action="contact.php">
Name<BR>
<INPUT TYPE="text" NAME="name" SIZE="40"><BR>
E-mail address<BR>
<INPUT TYPE="text" NAME="email" SIZE="40"><BR>
Subject<BR>
<INPUT TYPE="text" NAME="subject" SIZE="40"><BR>
Your message<BR>
<TEXTAREA NAME="message" COLS="40" ROWS="5"></TEXTAREA><BR>
<INPUT TYPE="submit" VALUE="Send">
<INPUT TYPE="reset" VALUE="Reset">
</FORM>

Here is the php script....

<?php
$to = "nospam@removed.com";
$subject = "Mesquite Christmas Inquiry";
$name = $_REQUEST['name'] ;
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
$headers = "From: $email";
$sent = mail($to, $subject, $name, $message, $headers) ;
if($sent)
{print "Thank You, Your e-mail was successfully sent. We will be back in contact with you as soon as possible"; }
else
{print "We encountered an error sending your e-mail. Please check the form and try again."; }
?>

Here is a link to the contact page. I would like to keep the form as is, but I am open for an easier or better suggestion on the php script.

http://www.mesquitechristmas.com/contact_us.html

Any help would be greatly appreciated.

-Thanks

    {print "Thank You, $name,  Your e-mail was successfully sent. ... "

      also what is going on here...?

      $sent = mail($to, $subject, $name, $message, $headers) ; 

      this is only what it can contain...

      mail ( string $to , string $subject , string $message [, string $additional_headers [, string $additional_parameters ]] )

        try this,

        $to = "nospam@removed.com"; 
        $subject = "Mesquite Christmas Inquiry"; 
        $name = $_POST['name'] ; 
        $email = $_POST['email'] ; 
        $formMessage = $_POST['message'] ;
        $message =  "This Message Is From" . $name . " , " . $formMessage;
        $headers = "From: $email"; 
        $sent = mail($to, $subject, $message, $headers) ; 
        

          $sent = mail($to, $subject, $name, $message, $headers) ;

          This still won't work, as you're sending a $name variable where it doesn't belong.

          $to = 'email@test.com';
          $subject = 'Testing';
          $email = $_POST['email'];
          $formMessage = $_POST['message'];
          $headers = 'From: '.$email."\r\n".'Reply-To: '.$email."\r\n";
          $sent = mail($to, $subject, $message, $headers);
          

          also, as greensweater pointed out, you may want to move your print statement onto it's own line, that could be causing a problem. Try putting error_reporting(E_ALL); at the top of your script so we can see any errors it's throwing, too.

            SORRY - i pointed this out in my post (4) and forgot to take it out when i copied and pasted it 🙁

              Ok I have used some of the soltions here an got it work. Just need to fix some cosmetic things

              $message =  "New Message From [COLOR="Red"]NEED SPACE HERE[/COLOR]" . $name . " ,[COLOR="Red"]START NEW LINE[/COLOR] " . $formMessage;

              View the text in red above with that I need. I added HTML between the " "for a space and then a line break but it didn't work. Did I do something wrong. This is how I had it below.

              $message =  "New Message From &nbsp;" . $name . " ,<br /> " . $formMessage;

              What am I missing?

              Thanks

                You're missing Content-Type: text/html in your $headers variable (don't forget to separate multiple headers by \r\n).

                  I understand what you are saying but not sure how or where to do that. I don't work with php all the time just enough to get me by. So I have forget a lot of how to do stuff. Here is the code I am using....

                  <?php
                  $to = "nick@nospam.com";
                  $subject = "Mesquite Christmas Inquiry";
                  $name = $_POST['name'] ;
                  $email = $_POST['email'] ;
                  $formMessage = $_POST['message'] ;
                  $message =  "New Message From&nbsp;" . $name . " ,<br /> " . $formMessage;
                  $headers = "From: $email";
                  $sent = mail($to, $subject, $message, $headers) ; 
                  if($sent)
                  {print "Thank You, $name, Your e-mail was successfully sent. We will be back in contact with you as soon as possible"; }
                  else
                  {print "We encountered an error sending your e-mail. Please check the form and try again."; }
                  ?>
                  

                  Would it be done like this?

                  <?php
                  $to = "nick@nospam.com";
                  $subject = "Mesquite Christmas Inquiry";
                  $name = $_POST['name'] ;
                  $email = $_POST['email'] ;
                  $formMessage = $_POST['message'] ;
                  $message =  "New Message From&nbsp;" . $name . " ,<br /> " . $formMessage;
                  $headers = "\r\nContent-Type: text/html\r\nFrom: $email";
                  $sent = mail($to, $subject, $message, $headers) ; 
                  if($sent)
                  {print "Thank You, $name, Your e-mail was successfully sent. We will be back in contact with you as soon as possible"; }
                  else
                  {print "We encountered an error sending your e-mail. Please check the form and try again."; }
                  ?>

                  -Thanks

                    Close - you only need to separate multiple headers with a line break, so just remove the extra one at the beginning and that should work.

                      Thank you for your help, that did work. One other small thing I have noticed that I have done. Mind you I was donig all this at 5-6am without having to been to sleep yet. I set a defined subject in on the php side as you will notice above. BUT of the HTML form side they are allowed to type their own subject. It doesn't go through because it is defined in the php so I would never see it. Now I know I can set a value on the text input side that already has the text field filled in or give them the option to change it to their own subject. What would I need to change to allow them to add their own subject.

                      For exmaple I change the form to this

                      <INPUT TYPE="text" NAME="subject" SIZE="40" VALUE="Mesquite Christmas Inquiry" >

                      that will shot on the html side. so what would I put on the php side. Does this make sense any?

                      I guess what I am trying to say is if I set the value in the HTML field on the form and they change it will it revert back to that value since it is set in the form? what would I need to add to the php side to allow this to accept the form value or whatever the person that is using the form subject to be?

                      -Thanks

                        $subject = "$_POST['subject'] ";

                        and in your form

                        <input type="text" name="subject" size="40" value="Message">

                          Be sure to add value="default text" for the <input> on subject, as well.

                          And benracer, what are you using to generate code? Or are you doing that by hand? I'm just curious, cause it's been deprecated for ages.

                            by hand and what does this mean? it's been deprecated

                              Yea I got it figured out, thank you for your help. The code above though you added " on "$_POST['subject'] "; by mistake. I just have a couple small things i want to modify but I am going to try figure it out first.

                              I use outlook and when the make comes in it shows it to be from a Email address instead of a name. So I want it to show the name in the from field but still be able to see the email & hit reply and pull up the email address. In order for me to do that thought I need to make the name and email required. I still think I might know how to do that but we will see.

                              -Thanks again.

                                benracer wrote:

                                by hand and what does this mean? it's been deprecated

                                Your code isn't standards-compliant, it's been deprecated.

                                And Dada - to make it work like you said, with the name and proper reply info, look back to one of my other posts in this thread.

                                $headers = 'From: '.$email."\r\n".'Reply-To: '.$email."\r\n"; 
                                

                                That line there is what you'll want to play with. Set From: to something like:
                                $name <$email>
                                and reply-to: to just $email.

                                Don't forget to mark this resolved if everything's taken care of.

                                  Ok I am a little thrown now. This is the header I am currently using that I just got working with the content type.

                                  $headers = "Content-Type: text/html\r\nFrom: $name";

                                  While that just shows the name it is from doesn't give a reply email to reply to.

                                  Your coding for the header is differently coded using a different menthod from the one above so I am not sure how to insert the Reply To in there that you have.

                                  $headers = 'From: '.$email."\r\n".'Reply-To: '.$email."\r\n";

                                  To do what I am wanting would this be correct?

                                  $headers = "Content-Type: text/html\r\nFrom: $name\r\nReply-To: $email";

                                  -Thanks

                                    Yes, that should work. Horizon simply used single quotes and concatenation instead of variable interpolation inside double quotes as you are doing. Either method will work - you can verify by echo'ing out the string.

                                    Why do you ask, did it not work?

                                      No the above did not work. While it is showing the From name it is not giving me a reply to email to reply to. I don't want to see the email in from part just the name. Then when I click reply it will fill in the reply email address from which it was sent from. I have the email varible in my email message but it would be nice to just be able to click reply and it show it. I would like for it to just show the name because otherwise I will think it is spam because I have like 10 other email accounts on my Outlook.

                                      Here is what I am working with now.

                                      <?php
                                      $yourwebsite = "Mesquite Christmas"; // Your website
                                      $recipientname = "Nick"; // Whats your name ?!
                                      
                                      $to = "nick@mesquitechristmas.com";
                                      $subject = $_POST['subject'];
                                      $name = $_POST['name'] ;
                                      $email = $_POST['email'] ;
                                      $formMessage = $_POST['message'] ;
                                      $message =  "Dear $recipientname, $name has sent you the following message to $yourwebsite from email address " . $email . ".<br /><br />" . $formMessage;
                                      $headers = "Content-Type: text/html\r\nFrom: $name\r\nReply-To: $email";
                                      $sent = mail($to, $subject, $message, $headers) ; 
                                      if($sent)
                                      {print "Thank You, $name, Your e-mail was successfully sent. We will be back in contact with you as soon as possible"; }
                                      else
                                      {print "We encountered an error sending your e-mail. Please hit the back button on your browser, check the form and try again."; }
                                      ?>

                                      -Thanks