Web Design Forums

PHP

Have questions about PHP? Ask them here and our experts will assist you before you know it! You can also find help in the documentation at PHP.net.

Creating a Dynamic PHP Email



Site of the Month Voting - Now Open. CAST YOUR VOTE NOW!

Reply
 
LinkBack Thread Tools
Old December 15 '07, 10:20 PM (#1)
ThePhoenix2006 is offline
WDF Member
 
ThePhoenix2006's Avatar
 
Join Date: March 2005
Location: Michigan
Posts: 88
ThePhoenix2006 is on a distinguished road
Creating a Dynamic PHP Email

I'm creating an online cashsheet form for my place of business. I have 5 different stores that need to send me their daily cashsheets. So far we are doing it by fax, but I wanted to be more advanced. So I have a created an HTML form:
HTML Code:
<form action="emailit2.php" method="post">

    <fieldset>
    <h1>
      <legend>
      <label>
      <input name="location" type="text" id="name" value="Type in location" />
      </label> 
      Cash Sheet</legend>
    </h1>
    
<table cellpadding="0" cellspacing="3" border="0" align="center" width="100%">
				<tr>
				  <td>
						Month:
						<select name="month">
							<option value="" selected="selected">-</option>
							<option value="01">January</option>
							<option value="02">February</option>
							<option value="03">March</option>
							<option value="04">April</option>
							<option value="05">May</option>
							<option value="06">June</option>
							<option value="07">July</option>
							<option value="08">August</option>
							<option value="09">September</option>
							<option value="10">October</option>
							<option value="11">November</option>
							<option value="12">December</option>
						</select>	&nbsp;				
						Day:
						<select name="day">
							<option value="" selected="selected">-</option>
							<option value="01">1</option>
							<option value="02">2</option>
							<option value="03">3</option>
							<option value="04">4</option>
							<option value="05">5</option>
							<option value="06">6</option>
							<option value="07">7</option>
							<option value="08">8</option>
							<option value="09">9</option>
							<option value="10">10</option>
							<option value="11">11</option>
							<option value="12">12</option>
							<option value="13">13</option>
							<option value="14">14</option>
							<option value="15">15</option>
							<option value="16">16</option>
							<option value="17">17</option>
							<option value="18">18</option>
							<option value="19">19</option>
							<option value="20">20</option>
							<option value="21">21</option>
							<option value="22">22</option>
							<option value="23">23</option>
							<option value="24">24</option>
							<option value="25">25</option>
							<option value="26">26</option>
							<option value="27">27</option>
							<option value="28">28</option>
							<option value="29">29</option>
							<option value="30">30</option>
							<option value="31">31</option>
						</select>&nbsp;
						Year:
						<input type="text" name="year" size="10" maxlength="4" value="" />
                        <br />
                        <br />
                        <table width="600" border="0">
          <tr>
                            <td align="right">Sebewaing</td>
                            <td align="center">Total Drawer</td>
                    <td align="center">Start Money</td>
                    <td align="center">Bag Money</td>
                          </tr>
                          <tr>
                            <td align="right">$.01:</td>
                            <td align="right"><label>
                              <input type="text" name="onect" id="1c" />
                            </label></td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">$.05:</td>
                            <td align="right"><label>
                              <input type="text" name="fivect" id="5c" />
                            </label></td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">$.10:</td>
                            <td align="right"><label>
                              <input type="text" name="tenct" id="10c" />
                            </label></td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">$.25:</td>
                            <td align="right"><label>
                              <input type="text" name="twofivect" id="25c" />
                            </label></td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                            <td align="right">&nbsp;</td>
                          </tr>
                          <tr>
                            <td align="right">$1.00:</td>
                            <td align="right"><label>
                              <input type="text" name="onedt" id="1d" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="oneds" id="1ds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="onedb" id="1db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">$5.00:</td>
                            <td align="right"><label>
                              <input type="text" name="fivedt" id="5d" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="fiveds" id="fiveds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="fivedb" id="5db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">$10.00:</td>
                            <td align="right"><label>
                              <input type="text" name="tendt" id="10dt" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="tends" id="10ds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="tendb" id="10db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">$20.00:</td>
                            <td align="right"><label>
                              <input type="text" name="twoodt" id="20dt" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="twoods" id="20ds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="twoodb" id="20db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">$50.00:</td>
                            <td align="right"><label>
                              <input type="text" name="fiftydt" id="50dt" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="fiftyds" id="50ds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="fiftydb" id="50db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">$100.00:</td>
                            <td align="right"><label>
                              <input type="text" name="hunderddt" id="100dt" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="hunderdds" id="100ds" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="hunderddb" id="100db" />
                            </label></td>
                          </tr>
                          <tr>
                            <td align="right">Totals:</td>
                            <td align="right"><label>
                              <input type="text" name="totald" id="totald" />
                            </label></td>
                            <td align="right"><label>
                              <input type="text" name="totals" id="totals" />
                            </label></td>
                            <td align="right"><label>
                            <input type="text" name="totalb" id="totalb" />
                            </label></td>
                          </tr>
                        </table>
<br />
						<input type="submit" name="button" id="button" value="Submit" />
						<input type="reset" name="button2" id="button2" value="Reset" /></td>
				</tr>
				</table>
  </fieldset></form>
And this is my php for the "attempted" HTML email output:

PHP Code:
<?
$location 
addslashes($_POST['location']);
$month addslashes($_POST['month']);
$day addslashes($_POST['day']);
$year addslashes($_POST['year']);
$onect addslashes($_POST['onect']);
$fivect addslashes($_POST['fivect']);
$tenct addslashes($_POST['tenct']);
$twofivect addslashes($_POST['twofivect']);
$totald addslashes($_POST['totald']);
$onedt addslashes($_POST['onedt']);
$fivedt addslashes($_POST['fivedt']);
$tendt addslashes($_POST['tendt']);
$twoodt addslashes($_POST['twoodt']);
$fiftydt addslashes($_POST['fiftydt']);
$fivect addslashes($_POST['fivect']);
$fivect addslashes($_POST['fivect']);
$fivect addslashes($_POST['fivect']);
$totald addslashes($_POST['totald']);
$oneds addslashes($_POST['oneds']);
$fiveds addslashes($_POST['fiveds']);
$tends addslashes($_POST['tends']);
$twoods addslashes($_POST['twoods']);
$fiftyds addslashes($_POST['fiftyds']);
$hundredds addslashes($_POST['hundredds']);
$totals addslashes($_POST['totals']);
$onedb addslashes($_POST['onedb']);
$fivedb addslashes($_POST['fivedb']);
$tendb addslashes($_POST['tendb']);
$twoodb addslashes($_POST['twoodb']);
$fiftydb addslashes($_POST['fiftydb']);
$hundreddb addslashes($_POST['hundreddb']);
$totalb addslashes($_POST['totalb']);

// multiple recipients
$to  'mvolz@ventronicpcsys.com' ', '// note the comma

// subject
$subject "$location $month $day $year";

// message
$message '
<html>
<head>
  <title><?= ("$location Cash Sheet $month $day $year") ?></title>
</head>
<body>
  <p><?php echo $location; ?></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: Mellisa Mathewson ' "\r\n";
$headers .= 'From: Totalcom <cashsheet@totalcom.us>' "\r\n";


// Mail it
mail($to$subject$message$headers);

header'Location: index.php' );
?>
The reason for the weird HTMl is just for testing. What I need is all of those dollar amounts to be tabled and dynamic according to each store. BUt I don't know the correct PHP code that i need to place within the '$message' to make the amounts show up.

Thanx guys
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 15 '07, 10:56 PM (#2)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,359
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
Right before this line: // multiple recipients
You would do all of the math using your variables.

Since they are entering the amounts of each bill in the form,
you could use Javascripting to do the totals automatically.
The totals would change each time they enter an amount
in a bill quantity text box.

The final totals would be sent with the form.

Do you really need to have all of the bill quantities emailed,
or just the totals of the three things?

You have them enter a location, so you already know where the
email comes from. You could instead have the employee log-in and
that solves a couple of issues ...

1) You would know the employee name and store location.
2) Anyone else entering the page with your form won't see it
unless they are logged-in. (a bit more secure).

So, you would be looking at a simple PHP script for user log-in & PHP sessions.
You can find those script examples using Google.

========

Then you have the added issue of what happens if the employee submits the
form and then realizes they made a mistake? Do they have to go and type it
all over again and resend? So, you might need a "confirmation page" that the
employee checks before submitting?

All of these questions add more to your script and involve more PHP scripting
than you might think you need. Faxing still looks like a good option to me because
the employee can write down amounts and see everything before they fax.

You may also look into using a PDF system where there is an online PDF form
that has input fields. The employee fills it out and transmits it to your email,
and a copy gets saved on a server. Might be nicer than an online form.
This requires an Adobe PDF writer (somewhat expensive).

EDIT:
Forgot to mention about your HTML.
You need to create a PHP HTML email instead of "plain text".
Use Google to search for: PHP HTML email


.

Last edited by mlseim; December 15 '07 at 10:59 PM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 16 '07, 03:17 AM (#3)
ThePhoenix2006 is offline
WDF Member
 
ThePhoenix2006's Avatar
 
Join Date: March 2005
Location: Michigan
Posts: 88
ThePhoenix2006 is on a distinguished road
Alrigt thanx for the reply, I do have htaccess on the server I just disabled it so i didn't have to go back into it evertime i wanted to test it.

Quote:
Since they are entering the amounts of each bill in the form,
you could use Javascripting to do the totals automatically.
The totals would change each time they enter an amount
in a bill quantity text box.

The final totals would be sent with the form.
I've been looking at a javascript that would do this.

Quote:
Do you really need to have all of the bill quantities emailed,
or just the totals of the three things?
I need all of the totals posted.

Quote:
Forgot to mention about your HTML.
You need to create a PHP HTML email instead of "plain text".
Use Google to search for: PHP HTML email
I've been looking for websites that show me how to include a php (variable?) into a HTML section of PHP Example:

PHP Code:
$message = ' 
<html> 
<head> 
  <title><?= ("$location Cash Sheet $month $day $year"?></title> 
</head> 
<body> 
  <p>
[COLOR="Blue"]<?php echo $location?>[/COLOR]
</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> 
';
I want to have a tabled nice organized email when I send this dynamic information. But I just don't know the command to do this. As you can see i've tryed echo and just a plain php insert and all it shows in the email is either $location blah blah. Or it won't show anything.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 16 '07, 10:54 AM (#4)
mlseim is offline
WDF Staff
 
mlseim's Avatar
 
Join Date: April 2004
Location: Cottage Grove, Minnesota
Posts: 3,359
mlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud ofmlseim has much to be proud of
There are two ways to send emails ... HTML or Plain Text.

See these examples on sending HTML emails:
http://www.google.com/search?hl=en&q=php+html+email

Sending HTML emails is a bit more elaborate.

I haven't looked into this one too much, but it says there
are several examples ... maybe it's worth looking at:
http://www.phpguru.org/static/mime.mail.html

As far as the rest of your needs, the Javascripting (totalizing)
would be the only other thing you need to work on.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 19 '07, 12:13 PM (#5)
imagn is offline
WDF Regular
 
imagn's Avatar
 
Join Date: July 2007
Location: Los Angeles
Posts: 156
imagn will become famous soon enough
Actually sending HTML emails from PHP is as easy as adding the proper headers:

$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

Then just construct your $body as you normally would.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Old December 20 '07, 08:21 AM (#6)
Steax is offline
Cookie Monster
 
Steax's Avatar
 
Join Date: December 2006
Location: Bandung, Indonesia
Posts: 1,208
Steax is a splendid one to beholdSteax is a splendid one to beholdSteax is a splendid one to beholdSteax is a splendid one to beholdSteax is a splendid one to beholdSteax is a splendid one to beholdSteax is a splendid one to behold
Quote:
Since they are entering the amounts of each bill in the form,
you could use Javascripting to do the totals automatically.
The totals would change each time they enter an amount
in a bill quantity text box.

The final totals would be sent with the form.
Use JS to make the totals, but have PHP count it out manually. Removes a weak link in your system.

Also, this is what you want to do:
PHP Code:

    PHP How do I post PHP blocks?
    $message = "
    <html> 
    <head> 
      <title><?= ("$location Cash Sheet $month $day $year"?></title> 
    </head> 
    <body> 
      <p>
    [color="Blue"]$location[/color]
    </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> 
    ";
Interestingly, the ones up top are proper. The important difference is that I'm using double quotes (") instead of single - variable insertion will only work with double quoted strings.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

  Web Design Forums » Programming Help » PHP

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Top 21 PHP Programming mistakes thexchord PHP 19 June 18 '10 02:20 PM
Creating games in PHP? riseofthevalk PHP 4 September 26 '07 01:24 AM
Creating multiple dynamic list boxes from mysql database phoenix211984 Database Systems Help 2 September 28 '06 02:59 AM
Creating PHP Images kleptos PHP 4 March 24 '04 06:18 PM
PHP and Send/Receive Email kleptos PHP 4 June 4 '02 03:50 PM

 
User Infomation
Your Avatar

Site Of The Month
Nominate Your Site Now!

Advertisement
WolfCMS.org

Latest Articles
- by RickM
- by bfsog

Advertisement

Partner Links



All times are GMT -4. The time now is 02:10 PM.


WebDesignForums.net is Copyright © 2010 RikeMedia.

SEO by vBSEO

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164