Jump to content

[SOLVED] Contact Form Help :)


bigrossco

Recommended Posts

I have the contact form below, but what I am wanting to do is make the input email address by the user, appear as the FROM address in the emails that are sent to the specified address:

 

          <form method="post" action="<?php echo($PHP_SELF) ?>">
<fieldset>
<legend>Contact Form</legend>
<p><label>Name:</label> 
   <input name="name" type="text" id="name" size="40">
</p>
<p><label>Email:</label> 
   <input name="email" type="text" id="email" size="40">
</p>
<p>
<label>Message:<br />
</label><textarea name="comments" cols="50" rows="10" id="comments"></textarea>
</p>
<p><input type="submit" name="submit" id="submit" value="Send Message"></p>
</fieldset>
</form>
<?php
  
  # Add your email address
  $to = 'test@test.com';
  # Add a default subject
  $subject = 'New Message Recived';
  
  $name = $_REQUEST['name'];
  $email = $_REQUEST['email'];
  $comments = $_REQUEST['comments'];
  $submit = $_REQUEST['submit'];

  $body = "$name $email $comments";

  if(isset($submit)) {

  mail($to, $subject, $body);}

  ?></

Link to comment
Share on other sites

$headers = "From: $email\n";

and this will alow for a auto fill after pushing "reply".

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

This is the way you formulate a mail header.

 

Then when you send the mail Do it in this order

 

mail($to, $subject, $body, $headers);

 

 

So what we end up with is this

 

<?  
  # Add your email address
  $name = $_REQUEST['name'];
  $email = $_REQUEST['email'];
  $comments = $_REQUEST['comments'];
  $submit = $_REQUEST['submit'];

  $to = 'test@test.com';
  # Add a default subject
  $subject = 'New Message Recived';
  $headers = "From: $email\n";
  $headers .= "Reply-To: $email\n\n";
  
   $body = "$name $email $comments";
  

  if(isset($submit)) {

  mail($to, $subject, $body, $headers);}

  ?>

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.