Results 1 to 4 of 4

Thread: Adding Plain Text Labels to PHP when submitted

  1. #1

    Adding Plain Text Labels to PHP when submitted

    Hi All,

    Thanks for reading. I am using Senoculers PHP mail form.

    Everything works. I just need to add labels to the form when it comes into the email.

    So name would be

    Name: Billy Bob
    Address: 123 Any
    City: Any City

    Here is a snippet of the PHP...

    $message = $_POST["name"] . $_POST["middle"] . $_POST["last_name"] ."\r\n".$_POST["street"] ."\r\n". $_POST["city"]


    Thanks for your help

    Justin

  2. #2

    Let me re-phrase this

    So I don't know PHP, I am just using preexisting code to submit a form and it works.

    When the form data is emailed, it arrives like this.

    Billy Bob
    123 Any St
    Any State
    800-888-8888

    and so on...

    So what I would like to know if it is possible to add a text label to the PHP so that when the form data arrives it looks like this.


    Name: Billy Bob
    Street: 123 Any St
    State: Any State
    Phone: 800-888-8888

    I am not sure if this is even possible.

    If it's not would I need to post it to an HTML file that has the labels?

    Any help would be great.

    Thanks,

    Justin

  3. #3
    18
    posts
    chown -R us ./base
    Firstly let me explain what the snippet you posted is doing so that you can understand this a bit better

    $message = $_POST["name"] . $_POST["middle"] . $_POST["last_name"] ."\r\n".$_POST["street"] ."\r\n". $_POST["city"]

    $message is the variable you are assigning a value to

    each of the $_POST[] items are the form items sent from the form using the post method

    the full stops . act as a joining character when building a string
    e.g: "a" . "b" . "c" = "abc"
    you can also combine it with = as follows
    $string = "a";
    $string .= "b"; (results in "ab")

    the \r\n codes designate line breaks

    So to add the labels in, just add the labels into the $message string (I've spaced this out over several lines to help clarify - there's no need to but imho it's good practice, especially when you're starting out).

    $message = "Name: " . $_POST["name"] . $_POST["middle"] . $_POST["last_name"] . "\r\n";
    $message .= "Street: " . $_POST["street"] ."\r\n";
    $message .= "City: ". $_POST["city"];

    hope this helps

  4. #4

    Thanks!

    Quote Originally Posted by DarkAz View Post
    Firstly let me explain what the snippet you posted is doing so that you can understand this a bit better

    $message = $_POST["name"] . $_POST["middle"] . $_POST["last_name"] ."\r\n".$_POST["street"] ."\r\n". $_POST["city"]

    $message is the variable you are assigning a value to

    each of the $_POST[] items are the form items sent from the form using the post method

    the full stops . act as a joining character when building a string
    e.g: "a" . "b" . "c" = "abc"
    you can also combine it with = as follows
    $string = "a";
    $string .= "b"; (results in "ab")

    the \r\n codes designate line breaks

    So to add the labels in, just add the labels into the $message string (I've spaced this out over several lines to help clarify - there's no need to but imho it's good practice, especially when you're starting out).

    $message = "Name: " . $_POST["name"] . $_POST["middle"] . $_POST["last_name"] . "\r\n";
    $message .= "Street: " . $_POST["street"] ."\r\n";
    $message .= "City: ". $_POST["city"];

    hope this helps


    ++++++++++++++++++++++++

    That worked! Thanks so much for taking the time to explain it.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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

Home About kirupa.com Meet the Moderators Advertise

 Link to Us

 Credits

Copyright 1999 - 2012