Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-17-2012, 03:31 PM   PM User | #1
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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.
docco is offline   Reply With Quote
Old 09-17-2012, 04:27 PM   PM User | #2
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Have a look into the example at http://php.net/manual/en/function.mail.php#example-3190
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
docco (09-20-2012)
Old 09-18-2012, 09:50 AM   PM User | #3
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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.
docco is offline   Reply With Quote
Old 09-18-2012, 11:45 AM   PM User | #4
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Have you tried that example in the link in my above post?
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
docco (09-20-2012)
Old 09-18-2012, 01:21 PM   PM User | #5
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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..
LearningCoder is offline   Reply With Quote
Old 09-18-2012, 03:34 PM   PM User | #6
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Not sure what's wrong with that link as it works well from my end.

Here's the code given there
Quote:
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);
?>
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Old 09-18-2012, 05:33 PM   PM User | #7
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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..
docco is offline   Reply With Quote
Old 09-19-2012, 09:10 AM   PM User | #8
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,678
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
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.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
docco (09-20-2012)
Old 09-19-2012, 05:13 PM   PM User | #9
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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
docco is offline   Reply With Quote
Old 09-19-2012, 05:43 PM   PM User | #10
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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?
docco is offline   Reply With Quote
Old 09-19-2012, 07:21 PM   PM User | #11
LearningCoder
Regular Coder

 
LearningCoder's Avatar
 
Join Date: Jan 2011
Location: The Pleiades
Posts: 849
Thanks: 67
Thanked 28 Times in 28 Posts
LearningCoder is an unknown quantity at this point
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.
LearningCoder is offline   Reply With Quote
Old 09-20-2012, 05:24 AM   PM User | #12
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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..
docco is offline   Reply With Quote
Old 09-20-2012, 06:17 AM   PM User | #13
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
docco (09-20-2012)
Old 09-20-2012, 06:18 AM   PM User | #14
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,198
Thanks: 59
Thanked 3,996 Times in 3,965 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
docco (09-20-2012)
Old 09-20-2012, 07:58 AM   PM User | #15
docco
New Coder

 
Join Date: Aug 2012
Posts: 67
Thanks: 18
Thanked 0 Times in 0 Posts
docco is an unknown quantity at this point
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..
docco is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 02:17 AM.


Advertisement
Log in to turn off these ads.