SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    USA, Pa. Philly
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question an email response ?



    I have a contact page on a site

    name, email address, and message

    is there a way that I can send a response email back to the sender automacilly, I know that it can be set up with host, but then that would be all email that comes in

    I have a thank you page that is redirected after they send

    Thx for your help

  2. #2
    Twitter: @AnthonySterling silver trophy AnthonySterling's Avatar
    Join Date
    Apr 2008
    Location
    North-East, UK.
    Posts
    6,111
    Mentioned
    3 Post(s)
    Tagged
    0 Thread(s)
    Security, filtering and validation aside, you would be looking for something like.
    PHP Code:
    <?php
    #send a message to you
    mail(
        
    'you@example.com',
        
    'New website contact',
        
    sprintf(
            
    '%s(%s), sent you a message: %s',
            
    $_POST['name'],
            
    $_POST['email'],
            
    $_POST['message']
        )
    );

    #send a message to them
    mail(
        
    $_POST['email'],
        
    'Thanks for your message',
        
    'Thank you for your recent message, the administrators at www.example.com will be in touch!'
    );

    #redirect
    header('Location: http://www.example.com/thanks.html');
    exit;
    ?>
    @AnthonySterling: I'm a PHP developer, a consultant for oopnorth.com and the organiser of @phpne, a PHP User Group covering the North-East of England.

  3. #3
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    USA, Pa. Philly
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thx I will give it a try,

  4. #4
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    USA, Pa. Philly
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question

    should this be the first code in page or after all other php code, thx

  5. #5
    SitePoint Zealot
    Join Date
    Nov 2004
    Location
    USA, Pa. Philly
    Posts
    127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    ok got it working, but was wondering what this code does or means

    '%s(%s), sent you a message: %s',

    Thx RJ

  6. #6
    SitePoint Addict Mal Curtis's Avatar
    Join Date
    Jul 2009
    Location
    New Zealand
    Posts
    327
    Mentioned
    14 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by RJweb View Post
    ok got it working, but was wondering what this code does or means

    '%s(%s), sent you a message: %s',

    Thx RJ
    That's part of the sprintf function

    PHP Code:
    sprintf(
            
    '%s(%s), sent you a message: %s',
            
    $_POST['name'],
            
    $_POST['email'],
            
    $_POST['message']
        ) 
    http://au.php.net/sprintf

    The first parameter is a string, the rest of the parameters replace the %s (or various other percent-character replacements - see manual) in order.

    Read the manual for a better explanation


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
  •