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 = '[email protected]';
  # 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
https://forums.phpfreaks.com/topic/61884-solved-contact-form-help/
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 = '[email protected]';
  # 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);}

  ?>

 

 

 

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.