Limitations of php mail script output?

max7
max7 used Ask the Experts™
on
Hello Experts,

I am working on a webform to email using PHP.  The script is capturing data from an online order form and sending via email to one recipient.

I had originally structured the email message with the form data to look like this:

Order one - Description: sweatpants, Color: black, Size: 78, 31, 100, 126, 50, 25, 652
Order two - Description: sweatpants, Color: ornge, Size: 78, 31, 100, 126, 50, 25, 652
Order three - Description: sweatpants, Color: ornge, Size: 78, 31, 100, 126, 50, 25, 652
Order four - Description: sweatpants, Color: ornge, Size: 78, 31, 100, 126, 50, 25, 652
Order five - Description: sweatpants, Color: ornge, Size: 78, 31, 100, 126, 50, 25, 652
Order six - Description: sweatpants, Color: ornge, Size: 78, 31, 100, 126, 50, 25, 652
New OS Client: no
Contact Info: Bob Smith, 123 Main Street, Waka, AK, Waka, 55555, bob@anyemail.com
Billing Info: Bob Smith,, 1234 Main Street, Waka, AK, 88888, bob@anyemail.com
Shipping Info: Bob Smith, 12345 Main Street, Waka, AK, 77777, bob@anyemail.com
Phone Numbers - Work: 719-270-5555, Mobile: 213-270-5555, Summer: 323-270-5555
Other comments: I am a new customer but not really ... I think you\'ve done some designs for me before so I wanted to contact you again and see if you guys still did business.  Thanks and I hope to hear from you soon.

They don't like this organization so they've requested something like this:

                                  Size  qty   size  qyt    size  qyt    size   qty    size   qty    size   qty   size    qyt
                               ----------------------------------------------------------------------------------------------------
tem Description       Adult    |     xs            s               m              l                 xl              2xl             3xl

                               Youth    |                    s               m              l                xl
--------------------------------------------------------------------------------------------------------------------------------
Item Description     Adult         xs            s               m              l                 xl              2xl             3xl

                               Youth                       s               m              l                 xl

I'm assuming I could do something like this in the email msg output area of the script (tell me if I'm wrong) but my question is: how far can go with this before it makes more sense to create a MySQL database and then grab information from there to output into in an email message or is there another way that would be a better choice which I haven't mentioned?  My assumption is to produce the result they want, creating a database and then extracting this information from it would be ideal in this situation.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
if you need to keep the data for a later use then yes crate a database
if you do not need that just crate an multidimensional array and iterate trough that

i hope this helps

Author

Commented:
>>>if you do not need that just crate an multidimensional array and iterate trough that

Pardon my ignorance, but what is a multidimensional array?  Can you point me to a resource on how it works?

Author

Commented:
and also what sort of results using such an array would produce ... I just got an email forwarded to me showing me what they had before it almost looks like a screenshot of the webform itself (just the form field elements as they would appear on the website but without colors or styles).  Is this what a multidimensional array would produce?
OWASP: Forgery and Phishing

Learn the techniques to avoid forgery and phishing attacks and the types of attacks an application or network may face.

here you can see the php manual with the array section
http://www.php.net/manual/en/language.types.array.php


in an array you can store data like this

$items[]=array("description"=>'sweatpants', 'color'=>'Black', 'size'=>'78, 31, 100, 126, 50, 25, 652');
$items[]=array("description"=>'sweatpants', 'color'=>'ornge', 'size'=>'78, 31, 100, 126, 50, 25, 652');
.......

foreach ($item as $orderno => $values){

echo"<br>Order $orderno";
echo "<br>Description".$values['description'];
echo "<br>Color".$values['color'];
echo "<br>Sizer".$values['size'];

}

Hope this helps
the multidimensional array it's used to store and manipulate the data easily. the layout and the way the data it's presented it's a diferent story.

please post the screenshot and maybe i can further asist you

Author

Commented:
>>>please post the screenshot and maybe i can further asist you

The image attached is of an email generated with the webform data from their site.  As you can see, the output is a two dimensional table that duplicates pretty much how the webform looks, except for colors or styles.  

Would I be able to do this via email by altering my php script?  If so, how time consuming would this be?

web-form-email-output.jpg
how do you get all the variables? in a $_POST variable?

why you do not make a table and insert all the values in to the coresponding cells?

the form has some limitations - as you can see for longer strings the text it's trimmed

hope this helps

Author

Commented:
>>> how do you get all the variables? in a $_POST variable?

Since this was created by some one else, I can't answer that.  Would it make sense to you to do such thing a using POST or GET?  I'm thinking POST ....

>>>why you do not make a table and insert all the values in to the coresponding cells?

Are you saying to make a table in my $msg output that basically recreates the webform tables?  If not, can you clarify this?

>>>the form has some limitations - as you can see for longer strings the text it's trimmed

Good point and I will mention this to the person.  Even if I were to create such an email output, it seems this aspect alone would be a deal killer in IMO.
>>> Are you saying to make a table in my $msg output that basically recreates the webform tables

Yes

try to figure out what variables are you geting and then try to insert them in the table

you can view the post data with this script placed at the begining of your script

echo"<pre>";
print_r($_POST);
echo"</pre>";

hope this helps

Author

Commented:
>>>try to figure out what variables are you geting and then try to insert them in the table

I know all the possible variables and those are already in place on the form.  Thing is, I need to set this form up and have the variable ready to catch the data as the user inputs it.  Perhaps I'm misunderstanding you here but it wouldn't be workable to try and figure out what variables any one user choose to enter on this form.  I need to be able to set it and foget it and have it send the email if you know what i mean.

Regarding recreating the webform tables in my $msg output area, what is the best way to go about this?  If I output markup (xhtml) how would I set it this so the script sends an email in html format so the mark up renders correctly?




here it's a sample script that sends emails in html format
<?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);
?> 

Open in new window

Author

Commented:
That did it ... thanks!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial