SitePoint Sponsor

User Tag List

Results 1 to 8 of 8

Hybrid View

  1. #1
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Problem with 'Reply-To' on PHP contact form...

    Hi guys,

    I've created a PHP contact form which works perfectly; except, when I receive the email to my inbox and go to reply to it, it doesn't reply to the email address of the person who submitted the form - in the reply field it appears to have the default server email address.

    Here's my code which I have included in the same PHP page as my form:

    Code:
    <?php
    
    if (array_key_exists('submit', $_POST)) {
        $name = $_POST['name'];
        $email = $_POST['email'];
        $formMessage = $_POST['message'];
    
    if (empty($name)) {
    $warning['name'] = "Please provide your name";
    }
    
    if (empty($email)) {
    $warning['email'] = "Please provide your email address";
    }
    
    if (empty($formMessage)) {
    $warning['message'] = "Please type your message";
    }
    
    $headers .= "Reply-To: " . $_POST["email"] . "\r\n";
    $to = "me@myemail.com";
    $subject = "Enquiry from website";
    
    $message = $headers;
    $message .= "Name: " . $_POST["name"] . "\r\n";
    $message .= "E-mail: " . $_POST["email"] . "\r\n";
    
    $headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    
    $message= "
    
    <table cellspacing='0' cellpadding='8' border='0' width='500'>
    <tr>
    <td colspan='2'></td>
    </tr>
    <tr bgcolor='#eeeeee'>
    <td width='154' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>Name</strong></td>
    <td width='314' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$name."</td>
    </tr>
    <tr bgcolor='#eeeeee'>
    <td style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>E-mail address:</strong></td>
    <td style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$email."</td>
    </tr>
    <tr bgcolor='#eeeeee'>
    <td colspan='2' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'><strong>Message</strong></td>
    </tr>
    <tr bgcolor='#eeeeee'>
    <td colspan='2' style='font-family:Verdana, Arial; font-size:11px; color:#333333;'>".$formMessage."</td>
    </tr>
    <tr><td colspan='2' style='padding: 0px;'></td></tr>
    </table>
    
    ";
     
    
    $url = stripslashes($_POST["url"]);
    if (!empty($url)) {
    header( 'Location: http://www.go-away-spam-robots.com' );
    exit();
    }
    
    if (!isset($warning)) {
    mail($to, $subject, $message, $headers);
    header( 'Location: http://www.mydomain.com/thankyou.php' ) ;
    }
    
    }
    
    ?>
    Can anyone see from my code why this would be happening?

    Thank you very much!

    SM

  2. #2
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Try add "From: " in $headers .
    Example:
    Code:
    $headers .= "From: " . $_POST["name"] . "<" . $_POST["email"] . ">\r\n";
    Or:
    Code:
    $headers .= "From: " . $_POST["email"] . "\r\n";
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  3. #3
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey there,
    Thank you for the reply - unfortunately I tried both and neither seemed to work; the email still comes from the default server user and replies to that.
    Any other suggestions?
    Thanks again

  4. #4
    SitePoint Addict
    Join Date
    Apr 2011
    Posts
    265
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    Maybe the cause is from the mail server that is configured to add that address to Reply if the connection is not with SMTP autentification.
    Try ask the server administrator.
    Free: Web Programming Courses HTML, CSS, Flash
    Web Programming: AJAX Course and PHP-MySQL Course video Lessons
    Good JavaScript and jQuery course for beginners

  5. #5
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you - I'll give them a shout!

  6. #6
    SitePoint Evangelist captainccs's Avatar
    Join Date
    Mar 2004
    Location
    Caracas, Venezuela
    Posts
    516
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    You don't need the "Reply-to:" header if you have the right "From:" header.

    Are you using mail() or imap_mail() to send the emails? I had a similar problem with imap_mail() on my server, it would not recognize my "Return-path:" header. I solved the problem by switching to mail().
    Denny Schlesinger
    web services

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2012
    Location
    Republic of Ireland
    Posts
    32
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You have concatenated your 'Reply-To' line without having anything to add it to first:
    PHP Code:
    $headers .= "Reply-To: " $_POST["email"] . "\r\n"
    It looks as though that gets dropped when you declare $headers as the MIME-Version further down the block:
    PHP Code:
    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n"
    I would concatenate the first line after the next two like so:
    PHP Code:
    $headers  "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "Reply-To: " $_POST["email"] . "\r\n"
    I use mail() myself and I've had no problems with it.

  8. #8
    SitePoint Enthusiast
    Join Date
    Feb 2010
    Posts
    74
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CASE CLOSED!!

    Thank you very much Enver, that's absolutely brilliant - that's solved the mystery!

    Also a big thank you to CaptainCSS and MarPlo for your invaluable contributions.

    Top shooters, all of you!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •