SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Contact form text

    Hi All,

    I'm just trying to finish off a contact from and have got stuck on one element. In the body of the text that is sent to the person I would like there name mentioned at a particular point ( highlighted in bold below - What do i put here?). Could some one let me know the code that would need to be added? Let me know if additional information is required.

    Many thanks,

    Keith

    $from = $_REQUEST['Email'] ;
    $company = $_REQUEST['Company'] ;
    $name = $_REQUEST['Name'] ;
    $headers = "From: $from";
    $subject = "Web Contact Data";

    $fields = array();
    $fields{"Name"} = "Name";
    $fields{"Company"} = "Company";
    $fields{"Email"} = "Email";
    $to = "me@myemail.co.uk";

    $body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }

    $headers2 = "From: me@myemail.co.uk";
    $subject2 = "text";
    $autoreply = "
    Thank you for registering with the xxxxxxxxxxxx. Please use your unique reference code attached below when making your booking.

    http://www.xxxxxxxx.org
    your name: (What do i put here?)
    Password: direct

    -------------------------------------------


    http://www.xxxxxxxx.org**
    Tel:
    F:
    E:
    *

    *
    Disclaimer
    *
    This e-mail is confidential and intended for the addressee (s) only. It may also be privileged. If you are not the intended recipient, please notify the sender by replying to this e-mail. You should not copy this e-mail or otherwise use it for any purpose and the contents must not be disclosed to any other person.";

    if($from == '') {echo "You have not entered an email, please go back and try again";}
    else {
    if($name == '') {echo "You have not entered a name, please go back and try again";}
    else {
    $send = mail($to, $subject, $body, $headers);
    $send2 = mail($from, $subject2, $autoreply, $headers2);
    if($send)
    {header( "Location: http://xxxxxxxxxxxx.co.uk/thankyou.html" );}
    else
    {echo "We encountered an error sending your mail, please notify webmaster@YourCompany.com"; }
    }
    }
    ?>
    <?php
    $headers = "From:codemiles@codemiles.com\r\n";
    $recipients = "me@codemiles.com,you@codemiles.com";
    mail($recipients, "This is the subject","This is the mail body", $headers);
    ?>

  2. #2
    It's all Geek to me silver trophybronze trophy
    ralph.m's Avatar
    Join Date
    Mar 2009
    Location
    Melbourne, AU
    Posts
    24,097
    Mentioned
    448 Post(s)
    Tagged
    8 Thread(s)
    How about

    PHP Code:
    $autoreply "Thank you for registering ... 
    Your name:" 
    .  $name .
    "Password: direct ... "
    Facebook | Google+ | Twitter | Web Design Tips | Free Contact Form

    Forum Usage: Tips on posting code samples, images and more

    Forrest Gump: "IE is like a box of chocolates: you never know what you're gonna get."

  3. #3
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi Ralph

    Thanks for your reply. I've tried adding the code and get a syntax error? I would not want to change any of the other elements of the form.

    Am i right in thinking that all of the body text that would appear in the email sits inside the " and "; If so the additional "; would effect the information after? Though I don't really any experience of php so kind of have no idea of what i'm talking about :/

  4. #4
    SitePoint Wizard silver trophybronze trophy Cups's Avatar
    Join Date
    Oct 2006
    Location
    France, deep rural.
    Posts
    6,869
    Mentioned
    17 Post(s)
    Tagged
    1 Thread(s)
    PHP Code:
    your name: (What do i put here?)
    Passworddirect 
    You use string concatenation (a dot .) to join the array field 'Name' (watch the case) into the string you already have:

    PHP Code:
    your name" . $fields['Name'] . "
    Passworddirect 
    Like you would in Javascript, but that uses a + sign to join bits of a string together.

  5. #5
    SitePoint Enthusiast
    Join Date
    Aug 2005
    Posts
    86
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for the reply. All seems to work now, so am very happy.


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
  •