Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Page 1 of 2 12 LastLast
Results 1 to 15 of 18

Thread: Submit form

  1. #1
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts

    Submit form

    I so far know that with submit form, I can send text in <textarea> to an email.
    I wonder that now can we send a page with table in it to email by using submit form?
    If it can be done, pls let me know what method to do, or a simple example is very appreciated.
    Thanks for any guide.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    docco (09-20-2012)

  • #3
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    Have a look into the example at http://php.net/manual/en/function.mail.php#example-3190
    Note:

    If intending to send HTML or otherwise Complex mails, it is recommended to use the PEAR package » PEAR::Mail_Mime.
    I have installed Mail_Mime 1.8.5 in my server, but do not know where to start.

  • #4
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Have you tried that example in the link in my above post?
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    docco (09-20-2012)

  • #5
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    922
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Your link doesn't seem to be working, abduraooft. I think it's a problem with php.net because the main site and other pages of that site are still working...

    docco, you just need to retrieve what the user has entered, save it into a variable, then concatenate that variable to your email body (if you want to send anything more than just the text).

    PHP Code:
    $text $_POST['name_of_input_element_in_html_form'];

    $email "your_email@domain.com";//for example
    $to $email;
    $subject "User Comments";
    $body "Another message has been sent to you"."<br />\n";
    $body .= "The message is as follows:"."<br />\n";
    $body .= $text;

    if(
    mail($to$subject$body)){
        echo 
    "Email Sent!<br />";
    }
    else{
       echo 
    "Error sending email.";

    You can also send additional header information along with the email. That is just a simple example for you.

    Regards,

    LC.
    Last edited by LearningCoder; 09-18-2012 at 01:23 PM.

  • #6
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Not sure what's wrong with that link as it works well from my end.

    Here's the code given there
    Example #4 Sending HTML email
    It is also possible to send HTML email with mail().
    PHP Code:

    <?php
    // multiple recipients
    $to  'aidan@example.com' ', '// note the comma
    $to .= 'wez@example.com';

    // subject
    $subject 'Birthday Reminders for August';

    // message
    $message '
    <html>
    <head>
      <title>Birthday Reminders for August</title>
    </head>
    <body>
      <p>Here are the birthdays upcoming in August!</p>
      <table>
        <tr>
          <th>Person</th><th>Day</th><th>Month</th><th>Year</th>
        </tr>
        <tr>
          <td>Joe</td><td>3rd</td><td>August</td><td>1970</td>
        </tr>
        <tr>
          <td>Sally</td><td>17th</td><td>August</td><td>1973</td>
        </tr>
      </table>
    </body>
    </html>
    '
    ;

    // To send HTML mail, the Content-type header must be set
    $headers  'MIME-Version: 1.0' "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' "\r\n";

    // Additional headers
    $headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' "\r\n";
    $headers .= 'From: Birthday Reminder <birthday@example.com>' "\r\n";
    $headers .= 'Cc: birthdayarchive@example.com' "\r\n";
    $headers .= 'Bcc: birthdaycheck@example.com' "\r\n";

    // Mail it
    mail($to$subject$message$headers);
    ?>
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #7
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    I think Example #4 Sending HTML email work w/o error because in this case it is the same with sending pure text that almost email senders such as formmail can do.
    I only think and do not test because this is not what I aim at. Moreover, thing I can not know that how user can copy html text to the message area.

    What I want is user can collect some items (such as shopping items). These items are shown dynamically in a table on a normal the submit form. The table will be sent along with the normal text.

    I try to study Perl Mail Mime but it seems very little document to guide about this.
    It is very appreciated if you can let me know what is the best formmail now?
    Last edited by docco; 09-19-2012 at 08:10 AM.

  • #8
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,852
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    What I want is user can collect some items (such as shopping items). These items are shown dynamically in a table on a normal the submit form. The table will be sent along with the normal text.
    In that example, the html markup is hard coded where as in your case you'd need to dynamically generate the html markup and append to the body of the email. This process won't have much difference even if you use Pear package.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • Users who have thanked abduraooft for this post:

    docco (09-20-2012)

  • #9
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by abduraooft View Post
    In that example, the html markup is hard coded where as in your case you'd need to dynamically generate the html markup and append to the body of the email. This process won't have much difference even if you use Pear package.
    Believe on you, I have checked your proposed code and the result make me astonished! There are a lot of thing I haven't know!!!
    Can you advise how and by what way, the user can insert html file into submit form to send it

  • #10
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LearningCoder View Post
    docco, you just need to retrieve what the user has entered, save it into a variable, then concatenate that variable to your email body (if you want to send anything more than just the text).

    You can also send additional header information along with the email. That is just a simple example for you.
    Thanks LC, you advice make me think much about this. But is a newbie, maybe there are something I do not know. Php is fixed in server side, and user only send email to server via submit form. And with submit form how can user add a table?

  • #11
    Regular Coder LearningCoder's Avatar
    Join Date
    Jan 2011
    Location
    The Pleiades
    Posts
    922
    Thanks
    76
    Thanked 29 Times in 29 Posts
    Not sure what you mean..

    You want to send the message to a database and then display the results to the html page?

    Regards,

    LC.

  • #12
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by LearningCoder View Post
    You want to send the message to a database and then display the results to the html page?
    LC.
    Can you expalin me know $text = $_POST['name_of_input_element_in_html_form'];
    So far, I build a submitform.htm, users access it, fill in their message here (only text in the textarea). After they submit, the form will be sent to my server.
    In my server, I upload a formmail.php to receive the form, process it and send the message from users to my email.

    What I want to do now is that the user can have a table in the submitform.htm and the formmail.php can process and send this table to my email.
    Last edited by docco; 09-20-2012 at 06:49 AM.

  • #13
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    Well, it's kind of ugly, but you could do this:
    Code:
    <form method="post" action="yourpage.php"
     onsubmit="this.theTable.value=document.getElementById('theTable').innerHTML; return true;">
    <input type="hidden" name="theTable" />
    ...
    </form>
    <table id="theTable">
    <tr>
        <td>.....</td>
        <td>.....</td>
        <td>.....</td>
    </tr>
    ...
    </table>
    See it? It simply copies the complete HTML of the table into a hidden form field, so then in your PHP code you can do
    Code:
    $tableHTML = $_POST["theTable"];
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    docco (09-20-2012)

  • #14
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,193
    Thanks
    75
    Thanked 4,341 Times in 4,307 Posts
    But there are probably better ways, but we can't know that until/unless we see your real page with the real form and the real table.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    docco (09-20-2012)

  • #15
    Regular Coder
    Join Date
    Aug 2012
    Posts
    121
    Thanks
    18
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Well, it's kind of ugly, but you could do this:
    Code:
    <form method="post" action="yourpage.php"
     onsubmit="this.theTable.value=document.getElementById('theTable').innerHTML; return true;">
    <input type="hidden" name="theTable" />
    ...
    </form>
    <table id="theTable">
    <tr>
        <td>.....</td>
        <td>.....</td>
        <td>.....</td>
    </tr>
    ...
    </table>
    See it? It simply copies the complete HTML of the table into a hidden form field, so then in your PHP code you can do
    Code:
    $tableHTML = $_POST["theTable"];
    Thanks, I am testing
    Last edited by docco; 09-20-2012 at 08:24 AM.


  •  
    Page 1 of 2 12 LastLast

    Posting Permissions

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