PHP - Php Mail From Multiple Result Sets
I would like to use the mail function to send an email to users from a database. I would like to pupulate the message body with records from a different table using another query.
anyone know how to do this? thanks Similar Tutorialsmysql_query("UPDATE mods SET version='$version' AND name='$title' AND descritpion='$description' AND lastupdate='$date' WHERE id='$id'"); I don't think I'm doing it correctly. :/ I have this code working fine (thanks to Thorpe). FYI, this code is getting info for each day and putting that info into the array and then later on a calendar is generated and the data gathered here is placed onto each specific day. This is working EXCEPT when there are MULTIPLE data sets on the SAME day. In those cases, it's just displaying the first data set. In other words, if $hunches['day'] = 3 and there is just one data set with that date, it will display that info on the calendar fine. But if there are five data sets with $hunches['day'] = 3, then it only displays the first one. I need it to display all data sets, so any clue how I could alter this code to do that? Code: [Select] $sql = "SELECT *, DATE_FORMAT(`dob`, '%e') AS day FROM hunches WHERE poolid = '{$_GET['poolid']}' AND (DATE_FORMAT(`dob`,'%m')) = " . $month1 . " ORDER BY day"; $gethunches = mysql_query($sql, $connection); if (!$gethunches) { die("Database query failed: " . mysql_error()); } else { while ($hunches = mysql_fetch_array($gethunches)) { $days1[$hunches['day']] = array(NULL,NULL,'<span class="red">' . $hunches['firstname'] . '</span>'); } } Here is a further explanation... Say $hunches['day'] = 5 and there are four data sets for that day (with respective firstnames of Bob, Joe, Jim and Tony). I would essentially need this to happen in the code... Code: [Select] $days1[$hunches['day']/*which would be 5 in this example*/] = array(NULL,NULL,'<span class="red">' . $hunches['firstname'] . '</span><br> <span class="red">' . $hunches['firstname'] . '</span><br> <span class="red">' . $hunches['firstname'] . '</span><br> <span class="red">' . $hunches['firstname'] . '</span>'); And that would then output... Bob Joe Jim Tony ...in the 5th day box on the calendar. Right now, I'm just getting... Bob I fear this is very complicated to do but holding out hope that there is some relatively easy way to make this work. Hi, i have a database with multiple records. One of those values is an image. When i query the database and i want only the images as a result it gives the result in a field. It then fills up the field horizontal and when there is no more field left it starts a new row. That is what i want. But now i want some extra info next to the picture so i put that in a table with two colums like this: echo '<table border="1" width="400"><td><a href="'.$row['website'].'"> <img src="'.$row['prod_img'].'"> '.$row['prod_name'].' <a href="'.$row['website'].'">'.$row['website'].'</td></table> ';}} But i still want the result to fill up the field and when the field is full i want the next results on a row below this.... Anyone? Hi There, I have an SQL query that returns 10 rows, which I want to echo over 2 columns and 5 rows, however, I want rows 1-5 on the left hand column and rows 6-10 on the right hand side. Is there an easy way to do this? Normally I would do a fetch_array but, that would place the rows in order of, left, right, left, right - if that makes sense? Table is a standard table with 2 columns and 5 rows. Thanks Matt Hi Guys, I have a HTML form which posts to a PHP mail script page. This data then emails to the company email address. I have two file attachments on my form: CV and Photo ID How do I integrate my php mail script to upload and then email these TWO files as TWO attachements on the email? $fileatt_cv $fileatt_id I have tried a few methods that I found on Google but they dont work Code: [Select] <?php // Grab Data from Form if(isset($_POST['submit'])) { // Personal Information $surname = mysql_real_escape_string($_POST['surname']); $firstname = mysql_real_escape_string($_POST['firstname']); $telephone = mysql_real_escape_string($_POST['telephone']); $mobile = mysql_real_escape_string($_POST['mobile']); $email = mysql_real_escape_string($_POST['email']); $address = mysql_real_escape_string($_POST['address']); $postcodep1 = mysql_real_escape_string($_POST['postcodep1']); $postcodep2 = mysql_real_escape_string($_POST['postcodep2']); $dob_dd = mysql_real_escape_string($_POST['dob_dd']); $dob_mm = mysql_real_escape_string($_POST['dob_mm']); $dob_yyyy = mysql_real_escape_string($_POST['dob_yyyy']); // Next of Kin $nextkinname = mysql_real_escape_string($_POST['nextkinname']); $nextkintel = mysql_real_escape_string($_POST['nextkintel']); // Availability $days_mon = mysql_real_escape_string($_POST['days_mon']); $days_tue = mysql_real_escape_string($_POST['days_tue']); $days_wed = mysql_real_escape_string($_POST['days_wed']); $days_thu = mysql_real_escape_string($_POST['days_thu']); $days_fri = mysql_real_escape_string($_POST['days_fri']); $days_sat = mysql_real_escape_string($_POST['days_sat']); $days_sun = mysql_real_escape_string($_POST['days_sun']); $availability_am = mysql_real_escape_string($_POST['availability_am']); $availability_pm = mysql_real_escape_string($_POST['availability_pm']); $availability_allday = mysql_real_escape_string($_POST['availability_allday']); $availability_requirements = mysql_real_escape_string($_POST['availability_requirements']); // Experience $experience = mysql_real_escape_string($_POST['experience']); // File Attachments $fileatt_cv = mysql_real_escape_string($_POST['fileatt_cv']); $fileatt_id = mysql_real_escape_string($_POST['fileatt_id']); // Rates $rate = mysql_real_escape_string($_POST['rate']); $rate_specific = mysql_real_escape_string($_POST['rate_specific']); // Employer Ref $employrefname = mysql_real_escape_string($_POST['employrefname']); $employrefcomp = mysql_real_escape_string($_POST['employrefcomp']); $employreftel = mysql_real_escape_string($_POST['employreftel']); $employrefadd = mysql_real_escape_string($_POST['employrefadd']); // Personal Ref $persrefname = mysql_real_escape_string($_POST['persrefname']); $persreftel = mysql_real_escape_string($_POST['persreftel']); $persrefadd = mysql_real_escape_string($_POST['persrefadd']); // Extra Information $allergy = mysql_real_escape_string($_POST['allergy']); $allergy_details = mysql_real_escape_string($_POST['allergy_details']); $drive = mysql_real_escape_string($_POST['drive']); $car = mysql_real_escape_string($_POST['car']); $criminal = mysql_real_escape_string($_POST['criminal']); $criminal_details = mysql_real_escape_string($_POST['criminal_details']); $howlongworkuk = mysql_real_escape_string($_POST['howlongworkuk']); $police_check = mysql_real_escape_string($_POST['police_check']); $right2work = mysql_real_escape_string($_POST['right2work']); $right2workna = mysql_real_escape_string($_POST['right2workna']); // Email Options $subject = "Test Company - Job Application"; $to = "test@test.com"; $mailheader = "From: $email" . "\r\n"; $mailheader .= 'MIME-Version: 1.0' . "\r\n"; $mailheader .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; // Applicants copy $mailheader .= "BCc: $email" . "\r\n"; // Message Content $body .= 'Message'; // End of Email Content > Display Message echo "Thank you. Your application was submitted to us successly. We review all applications carefully and we may contact you shortly."; // Attempt to Send Email mail($to, $subject, $body, $mailheader); } else { echo "Application Failed. Unfortunatley, there was a problem with your application and it was not submitted. Please try again later or alternativley please contact us."; } ?> Thanks in advanced. I'm trying to write a php page that displays data from a JOIN query for a specific ID table view brandinfo ID, brand, discounttype 1, antioni, no discount brandproducts brandID, producttype, price 1, Tshirt, 20.00 1, Pants, 30.00 1, Shoe, 40.00 the returned result is 1 antioni, no discount, Tshirt, 20.00, 2 antioni, no discount, Pants, 30.00 3 antioni, no discount, Shoe 40.00 The way I want the page to be displayed is ------------------ Antioni (at the top) Table 1. Tshirt 20.00 2. Pants 30.00 3. Shoe 40.00 no discount (at the bottom) ---------------------------- How should I construct the PHP page from the result since they're retrieved as rows? Magento PHP mail function : <?php class Gta_MerchantNotification_Model_Observer { public function merchantremainder($Observer) { $order = $Observer->getEvent()->getOrder(); $order_details = $order->getAllVisibleItems(); $itemData = array(); foreach ($order_details as $list) { $incrementid = $order->getIncrementId(); $sku = $list->getsku(); $name = $list->getName(); $price = $list->getPrice(); $Qty = $list->getQtyOrdered(); $extra = $order->getIncrementId(); $message = " <tr> <td>$incrementid</td> <td>$sku</td> <td>$name</td> <td>$price</td> <td>$Qty</td> </tr>"; $itemData[$list->getId()] = $message; } $finalMessage = "<table border='1'> <tr> <th>Id</th> <th>Sku</th> <th>Product name</th> <th>Price</th> <th>Qty Ordered</th> </tr>"; if (!empty($itemData)) { foreach ($itemData as $data) { $finalMessage .= $data; } $finalMessage .= "</table>"; $this->sendMail($finalMessage); } } public function sendMail($message) { $body ="$message"; $emailTemplate = Mage::getModel('core/email'); $emailTemplate->setFromName('abc'); $emailTemplate->setBody($body); $emailTemplate->setSubject("Custom Email from observer"); $emailTemplate->setType('html'); $emailTemplate->setToEmail('aveevacool@gmail.com'); $emailTemplate->send(); } } ?> Now my output like :
Edited January 7, 2020 by aveeva I have a notification system that notifies users of new comments, inside the email I have images, some of the logo, some of different people, everything shows up fine on my computer (yahoo email), however in the iPhones email application no images show up, there are just the blue squares with the question marks in them. I'm not sure what I'm missing. Code: [Select] $from = "Kithell <notifications@kithell.com>"; $headers = "From:" . $from ."\r\n"; $headers .= 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $subject = name($from_id, 'fl').$action; $message = '<html><body> <style>@charset "utf-8"; /* CSS Document */ .e-container { background-color: #FFF;position: relative;width: 90%;min-height:1px;margin-right: auto;margin-left: auto; } .e-container .e-m-header { padding: 2px; background-image: url(http://www.kithell.com/assets/tall-grey-header.png); background-repeat: repeat-x; border: 1px solid #CCC; background-position: bottom; display: block; text-align: center; } .e-container p { font-family: Arial, Helvetica, sans-serif; font-size: 12px; font-weight: normal; color: #666; vertical-align: text-top; display: inline-block; } .e-container .e-usr-photo { display: inline-block; margin: 10px; float: left; background-color: #F4F4F4; } .e-container p a { font-weight: bold; color: #3F60A3; text-decoration: underline; padding: 0px; float: left; margin-top: 0px; margin-right: 5px; margin-bottom: 0px; margin-left: 0px; } .e-container .e-quotes { font-size: 20px; font-weight: bold; color: #999; font-family: Tahoma, Geneva, sans-serif; display: block; padding: 0px; margin-top: 0px; margin-right: 0px; margin-bottom: 0px; margin-left: 75px; margin-top:10px; } .e-container .e-message { font-size: 13px; color: #333; padding: 0px; margin-top: 0px; margin-right: 10px; margin-bottom: 0px; margin-left: 10px; clear: none; display: inline; }</style> <div class="e-container"><div class="e-m-header"><img src="http://www.kithell.com/assets/kithell-logo.png" /></div><img class="e-usr-photo" src="http://www.kithell.com/'.photo($from_id, 55).'" /><br /><p><a target="_blank" href="http://www.kithell.com/#/profile&id='.$from_id.'">'.name($from_id, "fl").' </a> '.$action.'<div class="e-quotes">"<p class="e-message">'.nl2br(htmlentities(stripslashes($message))).'</p>"</div></p></div></body></html>'; mail($to,$subject,$message,$headers); Code: [Select] <?php $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $email = $_POST['email']; $dropdown = $_POST['dropdown']; $formcontent=" From: $firstname \n Surname: $lastname \n Email: $email \n Dropdown: $dropdown"; $recipient = "martin@sittingspiritually.co.uk, siobhan@sittingspiritually.co.uk"; $subject = "Newsletter Sign Up"; $mailheader = "From: $email \r\n"; mail($recipient, $subject, $formcontent, $mailheader) or die("Error!"); if ( mail($recipient, $subject, $formcontent, $mailheader) ){ header('Location: http://www.sittingspiritually.co.uk/thankyou.php'); } else { die ("error"); } ?> I have recently created a small snippet of php code for posting mail and it's sweet apart from 1 thing. I have two email addresses in the recipient section. It only sends to the last name in the list. Is this because i have written recipient? Should it be recipients? I need this mail to be delivered to both of the email addresses. I'm sure it's simple for someone with expert knowledge. Thanks in advance for any help. I am trying to send an e-mail message from a form, to each person in a MySQL database. In some cases, but not all, there are multiple e-mail address in the recordset. Each one should receive the same message addressed to them by name (FirstName and LastName) and e-mail address. I have tried "CONCAT_WS(' ', emailtest.Pri_EmailAddress, emailtest.Sec_EmailAddress, emailtest.Tri_EmailAddress) AS EmailTo" but it seems the relay account is rejecting the message if more than one address is in the EmailTo result. Any ideas or scripts that can do this would be appreciated. Thank you in advance for your help. This topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 Hello everyone, I have created a widget with php which allows users to put on their webpage and displays some information. To display the widget I am creating a javascript code for users to put on their websites. The javascript has a source of php page like src="widget.php?id=123" When they put the code on their websites php file is executed and displays some texts which is read from a remote XML file. There is no problem up to this point. But while I am reading from this XML file, the texts which are displayed on users webpage, are not in good format becouse I am converting string texts to ISO_8859-9 charset with "iconc" function. If the charset of webpage is ISO-8859-9 text are displayed correctly but if it is not, text are not displayed as expected. In example if the webpage charset is set to UTF-8, characters become unreadable. If I know the charset of webpage I can then convert strings to that charset. But could not find a predifined function thats doing this. Any idea about this problem ? or any other solutions you advice for this problem ? Thank you... i have an array with 5 numbers... Code: [Select] $numbers = array(1 => 4; 2 => 26; 3 => 15; 4 => 36 5 => 9); I need a method to combine them in sets of three.. For example: 4, 26, 15 4, 26, 36 4, 26, 9 and so on ... Have ten possible combinations. Any idea or advice of how i could do this...? Hello community, I am trying to create a login script, but in the HTTP Header it only sends the last cookie set. I first tried this code: $expire=time()+60*60*24; setcookie("gcg_user",$userid,$expire); setcookie("gcg_name",$username,$expire); setcookie("gcg_pass",$password,$expire); But it only set the gcg_pass cookie. Someone else suggested me to use header(): $expire=date(DATE_RFC822,time()+60*60*24); header('Set-Cookie: gcg_user="'.$userid.'"; expires='.$expire.';'); header('Set-Cookie: gcg_name="'.$username.'"; expires='.$expire.';',false); header('Set-Cookie: gcg_pass="'.$password.'"; expires='.$expire.';',false); But again it only sets the last cookie. The first code has been working fine on another server. Do I have to adjust anything in php.ini? Running XAMPP Lite: Quote ###### Apache Friends XAMPP Lite (Basis Package) version 1.7.3 ###### + Apache 2.2.14 (IPV6 enabled) ... + PHP 5.3.1 (PEAR) ... Any help on that? Thanks in Advance! I have had a thread here recently titled: Special Language characters doesn't display correctly. Now however, I have encountered a new problem with character sets, that I hope you can help me resolve! I find the concept of character sets quite confusing. When you are dealing with a database and want the content to be displayed on a web page, you obviously want it to be displayed correctly, and if you are not from an English speaking country, this could cause you some problems here and there due to international characters. As I have understood, one need to tell how the data (text) is stores in the database, how it is being interpreted (collation) and how it is being displayed on the web page.
Here is my situation:
One php page is displaying the content of a guestbook: show_content. This php file is divided into three parts: An include of a header.html file, a middle section displaying the content of the database and finally an include of a footer.html file to take care of the lower part of the page. Now, the header.html file does contain the script for a dropdown menu written in javascript:
header.html
<html> <head> <title>Guestbook</title> <meta http-equiv="Content-Language" content="da"> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> <LINK REL=stylesheet TYPE="text/css" HREF="generel/pop_style.css"> <LINK REL=stylesheet TYPE="text/css" HREF="generel/hoved.css"> </HEAD> <BODY leftmargin=0 topmargin=0 marginwidth=0 marginheight=0 background="generel/univback.gif"> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_core.js"></script> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_data.js"></script> <script type="text/javascript" language="JavaScript1.2" src="generel/pop_events.js"></script> <!--etc .......The main page controlling this header: show_content.php <?php function handle_fatal_errors() { if (http_response_code() == 500) {echo 'A technical error ocurred.';} } register_shutdown_function('handle_fatal_errors'); ini_set('display_errors', 0); include("header.html"); include("settings.php"); header('Content-Type: text/html; charset=utf-8'); //etc ...The footer.html file doesn't really matter here, so I avoid it. Now the strange thing: When I execute the show_content.php file above, the content of the database (guestbook) display perfectly, but the International letters in the dropdown menu don't display properly. BUT if I out-comment the following line: header('Content-Type: text/html; charset=utf-8');in the show-content.php file it is the opposite way around!! Then the items in the dropdown menu display properly while the content of the guestbook don't! By the way: When I connect to the database to store items, I do it with the following code: $db = new PDO('mysql:host='.$server.';dbname='.$database.';charset=utf8mb4', $username, $password);If somebody have an idea for an explanation of this behavior, I will be happy to hear about it! To me all these character set issues seem rather overwhelming. Maybe one setting override the other or what? NB! I also read that the people around the developement of PHP temporarily gave up on Unicode support for a PHP 6.0 version ... Erik Edited by erikla, 31 July 2014 - 06:29 PM. This topic has been moved to MySQL Help. http://www.phpfreaks.com/forums/index.php?topic=321612.0 I am really lost here with this date issue of mine. The below code is the last part of a query: Code: [Select] $defendercheck_3 = $row_checkifattacked3['atdate']; $defendercheck1_3 = strtotime("$defendercheck_3"); $defendercheck2_3 = date("D", $defendercheck1_3); The query does not return any results as expected, but when echoing the various steps I get following: echo "$defendercheck3"; = nothing (as expected) echo "$defendercheck1_3"; = nothing (as expected) echo "$defendercheck2_3"; = result! (NOT expected) why does it return anything on "date("D", $defendercheck1_3)" when "$defendercheck1_3" is blank? Ill spare you the full code because I don't think you'll need it to answer this, but I have code where an array called $days1 is being created. It's working fine as is to bring back 1 set of data, but I want to keep adding to the array for however many sets of data there are in the "while" statement. So my question is how do I write this so that ALL sets of data brought back by MySQL (whether it's 1 row or 50) keep getting added to the array, rather than just having one set of info in my array? I feel like I need to put "$days1 = array(" before the WHILE statement and then put the closing ")" after all the loops are done, but that didn't work. Can anyone help me out here? (assuming it makes sense )... Code: [Select] while ($hunches = mysql_fetch_array($gethunches)) { $days1 = array( $hunches['day']=>array(NULL,NULL,'<span class="red">' . $hunches['firstname'] . " " . $hunches['lastname'] . "-" . $hunches['dob'] . "--" . $hunches['sex'] . '</span>'), ); } I'm looking for a method to replace everything between brackets. The patterns that I'm looking for are defined: "/\[([2-9TJQKA][hdcs])\]/" The pattern inside the bracket could accur 2 or even 3 times inside the brackets. For example first occurance would be [Ac Kd], here I want to replace Ac into an imge and Kd too. Later in the text I will most of the time get 3 sets, instead of two: [Jc Td 9d]. The sets always consist of [2-9JQKA][hdcs] and also in this order. Another example: [2d 2s 2h], or [3s 4h 5c]. If I use the following function, it would not work optimally because some texts do contain some of those sets which should not be converted, ONLY the sets between the brackets: $haystack = setReplace($haystack); function setReplace($haystack) { $array = array("2s", "2h", "2d", "2c", "3s", "3h", "3d", "3c", "4s", "4h", "4d", "4c", "5s", "5h", "5d", "5c", "6s", "6h", "6d", "6c", "7s", "7h", "7d", "7c", "8s", "8h", "8d", "8c", "9s", "9h", "9d", "9c", "Ts", "Th", "Td", "Tc", "Js", "Jh", "Jd", "Jc", "Qs", "Qh", "Qd", "Qc", "Ks", "Kh", "Kd", "Kc", "As", "Ah", "Ad", "Ac"); for($i=0;$i < count($array);$i++) { $result = str_replace($array[$i], "<img src=\"/images/".$code[$i].".png\">",$haystack); } return $result; }Any ideas? Edited by dde, 20 January 2015 - 10:21 AM. Hi i have a form which display the date in the format that i want which is m/d/yyyy but then when i try update it sets the date back to 01/01/1970 help please this how the update script looks like <?php //Get the key field to be amended $news_id = $_GET['news_id']; $news_date = date('Y-m-d', strtotime($_GET['new_date'])); $subject = $_GET['subject']; $news_artical = $_GET['news_artical']; // check if there were any errors // check if there were any errors //$news_date = STR_TO_DATE('$news_date','%Y/%m/%d'); $query = "UPDATE news SET news_date = '$news_date', subject='$subject', news_artical='$news_artical' WHERE news_id = '$news_id'"; mysql_query($query) or die(mysql_error()); // execute query print "<p>The following records has been updated: </p>"; $result = mysql_query($query) ; //if there was a problem - get the error message and go back if (!$result) { echo "There were errors :<br>". mysql_error(); } else //OK, then the insertion was successful { //Create a new query to display the new row in a table $query = "SELECT news_id, news_date, subject, news_artical, DATE_FORMAT(news_date, '%d/%m/%Y') as new_date FROM news WHERE news_id = '$news_id' "; $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error()); echo "<table cellpadding=10 border=1>"; while($row = mysql_fetch_array($result)) { echo "<tr>"; echo "<td>".$row["news_id"]."</td>"; echo "<td><strong>" .$row["new_date"]."</strong></td>"; echo "<td><strong>".$row["subject"]."</strong></td>"; echo "<td width='55%'>".$row["news_artical"]."</td>"; echo "</tr>"; } //End while echo "</table>"; } //End Else insertion successful //End else successful Amendment ?> |