Everybody! This is important. In a few days, these forums will be moving over to using the totally sweet Discourse platform. To ensure this migration happens smoothly with no loss of content, these forums are currently in a read-only mode. I do apologize for the inconvenience.

There is never a good time to turn the forums off for an extended period of time, but I promise the new forums will be a billion times better. I'm pretty sure of it.

See you all on the other side in a few days, and if you have any (non-technical) questions, please e-mail me at kirupa@kirupa.com. For technical questions, try to find a tutorial that corresponds to what you are looking for and post in the comments section of that page.

Cheers,
Kirupa

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