how to code php to display email in columns and rows

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stealthmode
Forum Newbie
Posts: 4
Joined: Thu Dec 25, 2008 3:55 pm

how to code php to display email in columns and rows

Post by stealthmode »

Hi all,
I have been trying for weeks to get this to work but going round in circles.
I have a form with tons of fields.
I tried sending them as an html formatted table but it has serious issues so I send them as a simple text file instead.
I want to, if possible, divide the fields I send into two columns with rows in my email, is this possible with php?
I can post the script i use if this helps
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: how to code php to display email in columns and rows

Post by desperado »

please submit your script.
stealthmode
Forum Newbie
Posts: 4
Joined: Thu Dec 25, 2008 3:55 pm

Re: how to code php to display email in columns and rows

Post by stealthmode »

This script sends a simple non html email with all the fields from the form in list form.
My naminf of the fields can be changed but first I need it to send as two columns with one for the main applicant and the other for the joint applicant.

Code: Select all

<?php
$to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" ); 
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ; 
$name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ; 
$headers = "From: $from"; 
 
$subject = "Members Data From ......"; 
 
$fields = array(); 
$fields{"Member_Name"} = "Members Name";
$fields{"telephone"} = "Members Contact Phone Number"; 
$fields{"Email"} = "Members Email Address";
$fields{"Loan_Amount"} = "Loan_Amount £";
$fields{"title"} = "Main Applicants Title";
$fields{"surname"} = "Applicants Surname"; 
$fields{"forename"} = "Forename(s)";
$fields{"residential"} = "Residential Address";
$fields{"town"} = "Town";
$fields{"county"} = "County";
$fields{"postcode"} = "Postcode";
$fields{"years"} = "Lived At Address (Years)"; 
$fields{"months"} = "Lived At Address (Months)";
$fields{"hometelephone"} = "Home Tel No";
$fields{"mobile"} = "Mobile Tel No";
$fields{"dateofbirth"} = "D.O.B";
$fields{"nationality"} = "Nationality";
$fields{"sex"} = "Sex";
$fields{"marital"} = "Marital Status";
 
 
$fields{"homeowner"} = "Home Owner";
$fields{"tenant"} = "Tenant";
$fields{"livingwithfamily"} = "Living With Family";
$fields{"residentialother"} = "Living Other - Specify";
$fields{"numberathome"} = "No of Household At Home";
$fields{"numberworking"} = "No of Household Working";
 
 
$fields{"employedfulltime"} = "Employed - Fulltime";
$fields{"soletrader"} = "SoleTrader";
$fields{"partner"} = "Partner";
$fields{"director"} = "Director";
 
 
$fields{"occupation"} = "Occupation";
$fields{"employername"} = "Employers Name";
$fields{"employeraddress"} = "Employers Address";
$fields{"employertown"} = "Employers Town";
$fields{"employercounty"} = "Employers County";
$fields{"employerpostcode"} = "Employers Postcode";
$fields{"employeryears"} = "Years with Employer";
$fields{"employermonths"} = "Months with Employer";
$fields{"businesstelephone"} = "Employers Telephone Number";
$fields{"previousoccupation"} = "Previous Occupation";
$fields{"previousemployeryears"} = "Previous Employer Years";
$fields{"previousemployermonths"} = "previous Employer Months";
 
 
$fields{"sortcode"} = "Bank Sort Code";
$fields{"bankaccountno"} = "Bank Account Number";
$fields{"bankname"} = "Bank Name";
$fields{"bankaddress"} = "Bank Address";
$fields{"banktown"} = "Bank Town";
$fields{"bankcounty"} = "Bank County";
$fields{"bankpostcode"} = "Bank Postcode";
 
 
$fields{"bankyears"} = "How Long At Bank in Years?";
$fields{"bankmonths"} = "Months";
$fields{"chequecard"} = "Cheque Card";
$fields{"creditcard"} = "Credit Card";
$fields{"storecard"} = "Storecard";
 
 
$fields{"directcredit"} = "Method of Payment/Direct Credit";
$fields{"bacstransfer"} = "BACS Transfer";
$fields{"directdebitmandate"} = "Direct Debit Mandate";
 
 
$fields{"grossmonthlyincome"} = "Gross Monthly Income";
$fields{"regularincome"} = "Regular Overtime";
$fields{"spousegrossincome"} = "Spouse Gross Income";
$fields{"anyotherincome"} = "Any Other Income";
$fields{"totalgrossincome"} = "Total Gross Income";
 
 
$fields{"mortgagerent"} = "Mortage/Rent";
$fields{"counciltax"} = "Council Tax";
$fields{"loans"} = "Loans";
$fields{"creditcards"} = "Credit Cards";
$fields{"livingexpenses"} = "Living Expenses";
$fields{"totalexpenditure"} = "Total Expenditure";
 
 
$fields{"title1"} = "2 Title";
$fields{"surname1"} = "2 Surname";
$fields{"forname1"} = "2 Forename(s)";
$fields{"residential1"} = "2 Residential Address";
$fields{"town1"} = "2 Town";
$fields{"county1"} = "2 County";
$fields{"post1"} = "2 Postcode";
$fields{"years1"} = "2 Years Lived at Address";
$fields{"months1"} = "2 Months";
$fields{"hometelephone1"} = "2 Home Telephone";
$fields{"mobile1"} = "2 Mobile Telephone";
$fields{"dateofbirth1"} = "2 D.O.B";
$fields{"nationality1"} = "2 Nationality";
$fields{"sex1"} = "2 Sex";
$fields{"marital1"} = "2 Marital Status";
 
 
$fields{"homeowner1"} = "2 Homeowner";
$fields{"tenant1"} = "2 Tenant";
$fields{"livingwithfamily1"} = "2 Living With Family";
$fields{"residentialother1"} = "2 Living - Other";
$fields{"numberathome1"} = "2 Number in Household at Home";
$fields{"numberworking1"} = "2 Working ";
 
#Emplyment details 2
$fields{"employedfulltime1"} = "2 Employed Full Time";
$fields{"parttime1"} = "2 Part Time";
$fields{"selfemployed1"} = "2 Self-Employed";
$fields{"soletrader1"} = "2 Sole Trader";
$fields{"partner1"} = "2 Partner";
$fields{"director1"} = "2 Director";
$fields{"occupation1"} = "2 Occupation";
$fields{"employername1"} = "2 Employer Name";
$fields{"employeraddress1"} = "2 Employer Address";
$fields{"employertown1"} = "2 Employer Town";
$fields{"employercounty1"} = "2 Employer County";
$fields{"employerpostcode1"} = "2 Employer Post Code";
$fields{"employeryears1"} = "2 Employer Years";
$fields{"employermonths1"} = "2 Employer Months";
$fields{"businesstelephone1"} = "2 Business telephone";
$fields{"previousoccupation1"} = "2 Previous Occupation";
$fields{"previousemployeryears1"} = "2 Previous Employer Years";
$fields{"previousemployermonths1"} = "2 Previous Employer Months";
$fields{"sortcode1"} = "2 Bank Sort Code";
$fields{"bankaccountno1"} = "2 Bank Account No";
$fields{"bankname1"} = "2 Bank Name";
$fields{"bankaddress1"} = "2 Bank Address";
$fields{"banktown1"} = "2 Bank Town";
$fields{"bankcounty1"} = "2 Bank County";
$fields{"bankpostcode1"} = "2 Bank Post Code";
$fields{"bankyears1"} = "2 Bank Years";
$fields{"bankmonths1"} = "2 Bank Months";
$fields{"chequecard1"} = "2 Cheque Card";
$fields{"creditcard1"} = "2 Credit Card";
$fields{"storecard1"} = "2 Storecard";
 
$fields{"directcredit1"} = "2 Direct Credit";
$fields{"bacstransfer1"} = "2 BACS Transfer";
$fields{"directdebitmandate1"} = "2 Direct Debit Mandate";
$fields{"grossmonthlyincome1"} = "2 Gross Monthly Income";
$fields{"regularincome1"} = "2 Regular Overtime";
$fields{"spousegrossincome1"} = "2 Spouse Gross Income";
$fields{"anyotherincome1"} = "2 Any Other Income";
$fields{"totalgrossincome1"} = "2 Total Gross Income";
$fields{"mortgagerent1"} = "2 Mortgage/Rent";
$fields{"counciltax1"} = "2 Council Tax";
$fields{"loans1"} = "2 Loans";
$fields{"creditcards1"} = "2 Credit Cards";
$fields{"livingexpenses1"} = "2 Living Expenses";
$fields{"totalexpenditure1"} = "2 Total Expenditure";
$fields{"notes"} = "Notes and extra text to help with case";
 
$body = " You have received these contact details from ......:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); }
 
$headers2 = "From: me@somewhere.co.uk"; 
$subject2 = "Thank-you for filling in the Form "; 
$autoreply = "Somebody from.. will get back to you as soon as ......";
 
if($from == '') {print "You have not entered an Email Address, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a First Name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send){header( "Location: http://www.../r.../thankyou.html" );} 
else 
{print "We encountered an error sending your mail, please notify webmaster@someone.co.uk"; } 
 }
 }
?>
Thanks for looking, maybe I didn't need to post all the fields in the array.
User avatar
desperado
Forum Commoner
Posts: 46
Joined: Wed Dec 10, 2008 8:49 am

Re: how to code php to display email in columns and rows

Post by desperado »

i would suggest 2 arrays. one for each applicant. then you print 2 columns through a loop.

or the more primitive way would be to set up a html table and insert each variable where you want them.
stealthmode
Forum Newbie
Posts: 4
Joined: Thu Dec 25, 2008 3:55 pm

Re: how to code php to display email in columns and rows

Post by stealthmode »

hate to be really dumb, but at the moment I am. I need help to write the script.
2 arrays, would I simply add the $fields = array(); again to my script above the joint applicant fields?
If so, then how would I write the script to make it email two columns from what I have posted above. I told you I am usless at php but very slowly i'm trying to learn.
I have also redone the script to make the form data get processed into a table but it only processes a certain amount of the form fields then sends the email It will not go beyond a certain line.
Will I post the script I re-wrote to make it email as html with a table.
Either option of me getting the data as two columns I will be happy with. text email or html email.
Thanks if you can help me
stealthmode
Forum Newbie
Posts: 4
Joined: Thu Dec 25, 2008 3:55 pm

Re: how to code php to display email in columns and rows

Post by stealthmode »

I have come away from the array() and gone to table use.
Is this the correct way to write my script to use the $_POST to get the form field data?
So far the email comes as a nice formatted email with the form fileds set out the way I want them in the email. I am asking if there is a better way to write the code for the table as it doesn't seem to process the form after a few lines :cry:

Code: Select all

 
<?php
$to = ( isset ($_REQUEST['sendto']) ? $_REQUEST['sendto'] : "default 'to' email goes here" ); 
$from = ( isset ($_REQUEST['Email']) ? $_REQUEST['Email'] : "default 'from' email goes here" ) ; 
$name = ( isset ($_REQUEST['Member_Name']) ? $_REQUEST['Member_Name'] : "Default member name goes here" ) ; 
 
$headers = 
      'X-Mailer: PHP/' . phpversion() . "\r\n" .
      "MIME-Version: 1.0\r\n" .
     "Content-Type: text/html; charset=utf-8\r\n" .
     "Content-Transfer-Encoding: 8bit\r\n\r\n";
 
$subject = "Members Data From ......"; 
$body .= "<table align=left>";
$body .= "<tr>";
$body .= "<td width=\"200px\">Member Name</td><td width=\"200px\"> {$_POST['Member_Name']} </td><td width=\"200px\"></td><td width=\"200px\"></td>";
$body .= "</tr><tr>";
$body .= "<td>Members Contact Number</td><td> {$_POST['telephone']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Members Email Address</td><td> {$_POST['Email']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Loan Amount</td><td> {$_POST['Loan_Amount']} </td>";
$body .= "</tr>&nbsp;<tr>";
$body .= "<td>&nbsp;</td>";
 
//applicant details
$body .= "</tr><tr>";
$body .= "<th>Main Applicant</th><td>&nbsp;</td><th>Joint Applicant</th>";
$body .= "</tr><tr>";
$body .= "<td>Title</td><td> {$_POST['title']} </td><td>Title</td><td> {$_POST['title1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Surname</td><td> {$_POST['surname']} </td><td>Surname</td><td> {$_POST['surname1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Forname(s)</td><td> {$_POST['forename']} </td><td>Forename(s)</td><td> {$_POST['forname1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Residential Address</td><td> {$_POST['residential']} </td><td>Residential Address</td><td> {$_POST['residential1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Town</td><td> {$_POST['town']} </td><td>Town</td><td> {$_POST['town1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>County</td><td> {$_POST['county']} </td><td>County</td><td> {$_POST['county1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Post Code</td><td> {$_POST['postcode']} </td><td>Post Code</td><td> {$_POST['post1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Lived At Address(Years)</td><td> {$_POST['years']} </td><td>Lived At Address(Years)</td><td> {$_POST['years1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Lived At Address (Months)</td><td> {$_POST['months']} </td><td>Lived At Address (Months)</td><td> {$_POST['months1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Home Tel No.</td><td> {$_POST['hometelephone']} </td><td>Home Tel No.</td><td> {$_POST['hometelephone1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Mobile Tel No.</td><td> {$_POST['mobile']} </td><td>Mobile Tel No.</td><td> {$_POST['mobile1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>D.O.B</td><td> {$_POST['dateofbirth']} </td><td>D.O.B</td><td> {$_POST['dateofbirth1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Nationality</td><td> {$_POST['nationality']} </td><td>Nationality</td><td> {$_POST['nationality1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Sex</td><td> {$_POST['sex']} </td><td>Sex</td><td> {$_POST['sex1']} </td>";
$body .= "</tr><tr>";
$body .= "<td>Marital Status</td><td> {$_POST['marital']} </td><td>Marital Status</td><td> {$_POST['marital1']} </td>";
$body .= "</tr></table>";
 
$headers2 = "From: me@somewhere"; 
$subject2 = "Thank-you for filling in the Form "; 
$autoreply = "Somebody from.. will get back to you as ......
 
if($from == '') {print "You have not entered an Email Address, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a First Name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 
if($send){header( "Location: http://www...../r../thankyou.html" );} 
else 
{print "We encountered an error sending your mail, please notify .......@.com"; } 
 }
 }
?> 
 
This is the email I get:

Members Data from.....

Robert. You have received these contact details .com:

Member Name qwerty
Members Contact Number 012345
Members Email Address me@someone.com
Loan Amount 20,000

Main Applicant Joint Applicant
Title Mr Title Miss
Surname Mouse Surname Mouse
Forname(s) Mickey Forename(s) Minnie
Residential Address Hollywood Residential Address Hollywood
Town Space Town Space
County Universe County Universe
Post Code AB1 4ED Post Code CD1 3EW
Lived At Addre

The email is formatted in a table better than the text I have taken from the email above
Problem I'm having is the script doesn't seem to process past the last line above :banghead:
I know this is maybe a big problem but any help will be appreciated.
Post Reply