Reply to email address given

Discussion in 'PHP' started by caligrafx, Feb 23, 2010.

  1. #1
    I use a php contact form that when I get a email from it says its from the email address I have in send from field in the php, but the question I have is, how do I go about getting their email address to come up as from and when I hit reply I don't have to put there email address in the send to field.

    Here is a look at my php!

    Thanks,
    Adam

    
    <?php
    
    $EmailFrom = "noreply@url.com";
    $EmailTo = "adam@url.com";
    $Subject = "Contact Question";
    $Name = Trim(stripslashes($_POST['Name'])); 
    $Email = Trim(stripslashes($_POST['Email'])); 
    $Subject = Trim(stripslashes($_POST['Subject'])); 
    $Message = Trim(stripslashes($_POST['Message'])); 
    
    // validation
    $validationOK=true;
    if (!$validationOK) {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
      exit;
    }
    
    // are you human?
    if ($_POST['human'] == "eFT6GL") {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
    } else {
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
      exit;
    }
    
    // prepare email body text
    $Body = "";
    $Body .= "Name: ";
    $Body .= $Name;
    $Body .= "\n";
    $Body .= "Email: ";
    $Body .= $Email;
    $Body .= "\n";
    $Body .= "Subject: ";
    $Body .= $Subject;
    $Body .= "\n";
    $Body .= "Message: ";
    $Body .= $Message;
    $Body .= "\n";
    
    
    
    // send email 
    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    
    // redirect to success page 
    if ($success){
      print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
    }
    else{
      print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
    }
    ?>
    
    PHP:
     
    Last edited: Feb 23, 2010
    caligrafx, Feb 23, 2010 IP
  2. danx10

    danx10 Peon

    Messages:
    1,179
    Likes Received:
    44
    Best Answers:
    2
    Trophy Points:
    0
    #2
    If I understand you correctly...

    Replace:

    $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");
    PHP:
    with:

    $success = mail($EmailTo, $Subject, $Body, "From: <$Email>");
    PHP:
    Also, please consider validating the content (ie. $Email, and all other user submitted data) - this will help prevent spam.
     
    danx10, Feb 23, 2010 IP
  3. caligrafx

    caligrafx Active Member

    Messages:
    137
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    83
    #3
    That was exactly what I was looking for! Thanks once again!

    Thanks,
    Adam
     
    caligrafx, Mar 5, 2010 IP