Email Edited HTML Output of an Oracle SQL Query - php

Thank you for anyone who can help me with this!
What i have is an oracle database and i display all open work tickets using while and oci_fetch_row (page pickupready.php).
Each row is displayed in the table and has a checkbox to click on. User clicks multiple checkboxes selecting the rows (work tickets) they need and click Submit button.
New page (sendpickup.php) opens only showing table with rows that were selected by user. Then user has an ability to type quantity for each of the rows and then they click Send Pickup button which should email this output with their entered quantities and pickup times.
My question is how to grab everything that was output on that page + user edited information and email it using php mail() function?
This is my sendpickup.php page:
echo "<form action='' method='post'>";
echo "<table class = 'pickup'>\n";
echo "<tr style='background-color: orange'>\n";
echo "<th>CXL Date</th><th>Customer</th>";
echo "<th>WO #</th><th>Lot #</th><th>Style</th><th>Color</th><th>Original Qty</th>";
echo "<th>Cut Qty</th><th>Cut Date</th><th>Pickup Qty</th><th>Pickup Time</th>";
echo "</tr>";
echo "<tr style='background-color: #FFFFFF'>\n";
echo "<td>".($row[1] !== null ? htmlentities($row[1], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[2] !== null ? htmlentities($row[2], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[3] !== null ? htmlentities($row[3], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[4] !== null ? htmlentities($row[4], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[5] !== null ? htmlentities($row[5], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[6] !== null ? htmlentities($row[6], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[7] !== null ? htmlentities($row[7], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[8] !== null ? htmlentities($row[8], ENT_QUOTES) : " ")."</td>\n";
echo "<td>".($row[9] !== null ? htmlentities($row[9], ENT_QUOTES) : " ")."</td>\n";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = $row[8]></td>";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = '9 AM'></td>";
echo "</tr>\n";
echo "</table>";
echo "<input type='submit' name = 'sendpickup' value='Send Pickup'>";
echo "</form>";
Then i use following to send an email:
if (isset($_POST['sendpickup']))
{
$to = 'wip#abc.com';
$subject = 'READY FOR PICKUP';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: WIP <wip#abc.com>' . "\r\n";
$headers .= 'From: ABC User<wip#abc.com>' . "\r\n";
mail($to, $subject, $message, $headers);
header( 'Location: pickupready.php');
}
Basically my page sendpickup.php works correctly, mail() function works too and my only problem is how to grab data for my $message variable.
i can use grab everything from sql output and assign to this variable but i cannot figure out how to send user information filled out in these 2 input boxes:
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = $row[8]></td>";
echo "<td><input size= '5' style = 'color: red; font-weight: bold' value = '9 AM'></td>";
so as of right now i do something very basic. I select my output table by dragging mouse over it, then use a copy paste into email and email it manually. It works for time being but i really want to automate this and yet can't figure out how. I apologize if this was asked before - i tried to search but couldn't find any information and i cannot figure it out myself.
thank you again!

Related

Pulling mySQL data and placing inside a variable in PHP

I'm trying out something like below. I get to successfully display the $Message without the PHP script that you see in the middle.
$Message = "<table><tr><td>" <?php code A ?>"</td></tr></table>";
The "Code A" PHP script meant to pull some date from an SQL database and present inside a table as you would see.
I see with this code not working, the issue is the way I place the PHP script inside $Message.
Would like to know, first is this really possible to have a script running attempting to pull data from an mySQL database and assign the output to a variable and if so how should the script look like otherwise?
Here's the full code which represent Code A, if that helps in understanding the issue better.
<?php
if(!isset($_POST['savedata']))
{
echo 'some text message';
}
else
{
include ('dbconnect/index.php');
$SQLuserpw="SELECT * FROM USER WHERE EMAIL = '".htmlspecialchars($email)."'";
$user=mysqli_query($conn, $SQLuserpw) or die ('SQL Error');
$pendingRow=mysqli_num_rows($user);
if($pendingRow == '')
{ echo 'some text here';} else
{
while ($reK = mysqli_fetch_array($user))
{
$wec = $reK['FNAME']; $wec2 = $reK['LNAME']; $wec3 = $reK['EMAIL'];
echo '<table>';
echo '<tr><td>First Name</td><td> : </td><td>'.$reK['FNAME'].'</td></tr>';
echo '<tr><td>Last Name</td><td> : </td><td>'.$reK['LNAME'].'</td></tr>';
echo '<tr><td>Email</td><td> : </td><td>'.$reK['EMAIL'].'</td></tr>';
}
echo '</table>';
}
}
?>
UPDATE
Suggestion made by #ADyson works.
if the code piece you've shared is working, do it like that,
$message = '<table>';
$message .= '<tr><td>First Name</td><td> : </td><td>'.$reK['FNAME'].'</td></tr>';
$message .= '<tr><td>Last Name</td><td> : </td><td>'.$reK['LNAME'].'</td></tr>';
$message .= '<tr><td>Email</td><td> : </td><td>'.$reK['EMAIL'].'</td></tr>';
}
$message.= '</table>';
the use $message wherever you want.

Getting random Blank email while using nested while loop

1st, I know mysql_ is outdated and I should use mysqli (unfortunatly, I inherited this system and its way too much work to change it over at the present time)
The problem I have is when I execute the code, I am getting random blank emails. This system loops through a list of stores in a database and lists the information in a table for the store managers. It doesnt really matter what information is being presented. Does anyone see anything right off hand that micht cause this problem?
while($store = mysql_fetch_array($result_store)){
#Updates the Report Date for each store in the Loop
$report_date = "UPDATE ActiveStores SET Report_Date = '$Today' WHERE StoreNumber = $store[StoreNumber]";
if (!mysql_query($report_date, $con)){
die('Error: ' . mysql_error());
}
#Selects data from ActiveStores for the current store in the loop
$result2 = mysql_query("SELECT * FROM ActiveStores WHERE StoreNumber = '$store[StoreNumber]' ORDER BY StoreNumber");
#Loops through the currently selected store and Creates an Array of the data
while ($row = mysql_fetch_array($result2)) {
#Sets Store Variable
$Store = $row['StoreNumber'];
echo '<table width="1110"><table width="1102"><tr>';
# To Email Address
#$emailaddress = '******#*****.com';
# Message Subject
$emailsubject= 'Testing Report - Store: ' . $Store;
#Turn on Output buffer for email
ob_start();
#Heading for Report
echo '<h2 class="blktext">Walgreens Weekly Report - ' . $Today . '<br /></h2>';
echo '<h2>Insurance Orders:</h2>';
#Cancelled Orders for the store this week
$result_cash_canceled = mysql_query("SELECT * FROM Orders WHERE StoreNumber = '$Store' AND Cancel = 'checked' AND Order_Type = 'Cash' AND Cancel_Date > '$Sevendaysback'");
$tot_ord_ins_prt = mysql_num_rows($result_cash_canceled);
if ($tot_ord_ins_prt !== 0){
echo '<h4 class="blktext">Cancelled Orders for the store this week</h4><span class="blktext">';
echo '<p><i>Fitter Action: Fitter to contact client to notify of cancelled order, if not initialed by client.</i></p>';
echo "<table border='4' class='rpttbl' frame='hsides' rules='rows' width='1400'>";
echo '<tr><th>Store #</th><th>Order #</th><th>Customer</th><th>Phone #</th><th>Cancel Date</th width="150"><th>Reason for Cancellation</th><th width = "150">Patient Notified<th></tr>';
while($row_cash_canceled = mysql_fetch_array($result_cash_canceled)){
echo "<tr>";
echo "<td align='center'>" . $row_cash_canceled['StoreNumber'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Order_ID'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_First_Name'] . " " . $row_bo['Cust_Last_Name'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cust_Phone'] . "</td>";
echo "<td align='center'>" . $row_cash_canceled['Cancel_Date'] . "</td>";
echo "<td align='center'> </td>";
echo "<td align='left'>( ) Called: Patient Cancelled notified<br />( ) Called: LVM for Patient</td>";
echo "</tr>";
}
echo "</table>";
echo "Total: " . $tot_ord_ins_prt;
echo'</span>';
}
#Message at bottom of email
echo '<br /><br /><br /><br /><p>Thank you for your prompt attention to this report.</p>';
echo '<p>If this report is blank in all the above sections, this means, at this point, we are not showing any active orders within our system.<br />';
echo 'If you feel this is in error, please contact our Customer Care team at: <strong>(***) ***-8125</strong></p>';
echo '<p>Please update this form with the appropriate action taken by patient, and fax back to: (866) 8**-**** OR email to: ******#*****.com</p>';
echo '<p>Fitter Name: ________________________________________</p>';
echo '<p>Comments: _______________________________________________________________<br />';
echo '_________________________________________________________________________</p>';
echo '<p>The information contained in this email, together with any attachments, is intended only for the use of the individual or entity<br /> to which it is addressed. It may contain information that is confidential and prohibited from disclosure. If you are not the intended <br />';
echo 'recipient, you are hereby notified that any dissemination, or copying, of this message or any attachment is strictly prohibited.</br> If you have received this message<br /> in error, please notify the original sender immediately by phone or by return email, </br>';
echo 'and delete this email, along with any attachments. <br />Receipt by anyone other than the intended recipient is not</br> a waiver of any privileged information. </p>';
}
$body=ob_get_contents();
ob_end_clean();
#$body = "** It is Imperative that you respond to this email. When you receive this please print it out, sign your name and store number and fax the form to ***-***-1161**<br /><br /><br />";
#$body .= "Name: <br /><br />Store #:";
$headers = 'From: Visual Footcare Technologies *****#****.com'.$eol;
$headers .= 'Reply-To: Visual Footcare Technologies *****#*****.com'.$eol;
$headers .= 'Return-Path: Visual Footcare Technologies <mcooper#visualfootcare.com>'.$eol; // these two to set reply address
#$headers .= 'Cc: ******#*****.com'.$eol;
$headers .= "Message-ID:<".$now." TheSystem#".$_SERVER['SERVER_NAME'].">".$eol;
$headers .= "X-Mailer: PHP v".phpversion().$eol; // These two to help avoid spam-filters
$mime_boundary=md5(time());
$headers .= 'MIME-Version: 1.0'.$eol;
$headers .= "Content-Type: multipart/related; boundary=\"".$mime_boundary."\"".$eol;
$msg = "";
$msg .= "Content-Type: multipart/alternative".$eol;
$msg .= "--".$mime_boundary.$eol;
$msg .= "Content-Type: text/html; charset=iso-8859-1".$eol;
$msg .= "Content-Transfer-Encoding: 8bit".$eol;
$msg .= $body.$eol.$eol;
$msg .= "--".$mime_boundary."--".$eol.$eol; // finish with two eol's for better security. see Injection.
then a standard mail(......) code to send the email and then ending the loop.
hope that makes sense.
try changing this
if ($tot_ord_ins_prt !== 0)
to
if ($tot_ord_ins_prt !== false)
MIME header blocks must be terminated by a blank line, even when used in a multi-part section. I don't know what you mean by "random", but I suspect that "blank emails" could be the result of your message body being interpreted as invalid MIME headers.
Insert a blank line between the last MIME header and your message body:
$msg .= $eol.$body.$eol.$eol;
If this doesn't help, you should probably show that "standard" mail line you mentioned. Since it's the one that actually sends the email, I'm surprised you didn't include it. You included a whole lot of other code. It would be good to see what you do with the two strings, $headers and $msg.

Adding embedded images within mail body phpmailer class

Im trying to embed an image within my message body but it ends up as an attachment
$mailer->Subject = APP_NAME . " - " . $name . " send you and Ad : " . $row['name'];
$mailer->IsHTML(true);
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
//footer
$footer = "Regards<br/><br/>";
$footer .= '<table style="width: 95%">';
$footer .= '<tr>';
$footer .= '<td>';
$footer .= "<strong><span style='font-size: 15px'>NamDimes Team</span></strong><br/>
NamDimes<br/>
Contact Number: " . APP_CONTACT . "<br/>
Email: " . APP_EMAIL . "<br/>
Website: " . APP_WEBSITE . "<br/>";
$footer .= '</td>';
$footer .= '<td style="text-align:right">';
$footer .= '<img src=\"cid:logoimg\" />';
$footer .= '</td>';
$footer .= '</tr>';
$footer .= '</table>';
$mailer->Body = $body . $footer;
$mailer->AltBody="This is text only alternative body.";
$mailer->AddAttachment('../' . $row['image_path'], $row['name'] . ".jpg");
i have set everything else, including the addresses, the mail gets send out, logo image that I want embed in the body gets attached as an attachment, anyone know why?
Don't use $mailer->AddEmbeddedImage, but directly add
<img src="http://.../images/namDiams.png" /> instead.
The mail length should be lighter... And it works.
EDIT
I don't know if it will help you but there is a little mistake here :
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDimes.png');
Should be
$mailer->AddEmbeddedImage('../images/namDiams.png', 'logoimg', 'namDiames.png');//the last param the second 'a' was missing...
Another topic here
I can confirm that user2189925's answer does work. However, I use the absolute path since the location of the calling script is more likely to change than the location of the image.
e.g.
<img src="C:\folder\images\namDiames.png" />
Faced the same problem, then I decided to replace the following
<img src="img/example.jpg"
with
<img src= "https://mysitename.com/img/example.jpg">
and it worked.
just give path of your image to the mail body eg: (img src="../images/cat.jpeg) it will definately work

can't get loop in mysql_fetch_array to print on separate lines

I am trying to loop through my mysql query result and print out some of the data. What I expected was when I added "\n" to the end of the print message, it would print each message on a separate line. But for some reason its all on one line. Why is this and how can I make each message be on a separate line?
while($row = mysql_fetch_array($result))
{
$message = $row['action_type'] . " " . $row['identifier'] . " # " . " placeholder ";
if($row['location'] !== NULL)
{
$message += " on " . $row['location'] . "\n";
}
echo $message . "\n";
}
Your $message variable is ending with a /n when it should be \n. Try updating it to fix (unless of course, in that section of the code it's on purpose):
$message += " on " . $row['location'] . "\n";
The actual echo statement ends with a real newline, so this should work properly in a command-line, but not in a browser.
To get it to display on a new line in a browser, change the \n instances to <br />:
echo $message . "<br />";

How do i add 'default text' in a php form

I'd like the following code to be change so that the textarea has a default value that disappears when it's focused.
if ($txtActive != 'N') {
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "";
echo "<tr>";
echo "<th align='" . $labelAlign . "'></th>";
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols'>" . stripslashes($value) . "" . "</textarea>";
echo ($txtError) ? "<br /><b style='color: $errorTxtColor;'>$txtError</b>" : '';
// echo "wendy TESTerburger";
echo "</td>";
echo "</tr>\n";
If I'm understanding the question properly, you would change this line, like so:
$value = (isset($_POST['mod_SEF_textarea'])) ? htmlspecialchars($_POST['mod_SEF_textarea']) : "Default Text";
So if mod_SEF_textarea was not set, i.e. no value, the false clause would execute, which would be your default.
Any client side interaction won't use PHP - but your in client friend, JavaScript.
I wrote a jQuery plugin that does this in a cross browser fashion.
If only targeting modern standards compliant browsers, use the placeholder attribute.
You need to use the placeholder attribute. Note that it's part of the HTML5 spec, only works with the latest versions of some browsers. If you want it to work in older browsers, you'll need to do it with Javascript.
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' placeholder='Default text'>" . stripslashes($value) . "" . "</textarea>";
Here's an example of doing it with Javascript:
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value=\'tester\' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Default value')this.value='';\" onblur=\"if(this.value=='')this.value='Default value';\">" . stripslashes($value) . "" . "</textarea>";
Very simple.
echo "<td><textarea class='SEFTextArea' name='mod_SEF_textarea' id='textarea' value='Comments...' rows='$txtRows' cols='$txtCols' onfocus=\"if(this.value=='Comments...')this.value='';\" onblur=\"if(this.value=='')this.value='Comments...';\">" . stripslashes($value) . "Comments..." . "</textarea>";

Categories