PHP - Server Mail Queue Handling Checking For Stalls And Optimising
Hi.
I am sending out email with a php script - about 5000 at a time by send 15 or so every 20 seconds which works fine. Sometimes I need to add an attachemnt. I then find that the script will keep stalling. Is there a way to test the server qmail/mail queue to see if it isready to send another message? - rather than send it and have the script stall? It may be enough to simply be able to check that the number of messages left to be sent in the queue? Have search a lot for help on this with no results. Any server/qmail experts out there? Thanks Paul Similar TutorialsThis topic has been moved to Other Web Server Software. http://www.phpfreaks.com/forums/index.php?topic=347009.0 $to=sammieave@ave.com,samuel@ave.com; $subject = "New Event Logged"; $message = "Test"; $headers = "From: Samuel<sammieave@ave.com>;\r\n"; $headers .= "Content-Type: text/html"; mail($to,$subject,$message,$headers); I am having the above code but unfortunately the error I am getting is: Warning: mail() [function.mail]: SMTP server response: 550 Requested action not taken: mailbox unavailable or not local in C:\xampp\htdocs\CRM\support\mailer.php on line 139 Hopefully there is a simple solution to this. I have a form that when submitted sends a message to an email address from the form. A customer fills it out, so there is no single one email address. However, half of the time, the retards that use this form dont know their own email address and dont bother to put the .net at the end of it. or they misspell it. The other half of the time they dont even bother to put the @ and the domain. They still think this is AOL for some god unknown reason. And I cant account for all the ways that they can not figure out how to fuck up their email address, so an email-validator doesnt work because they can even beat that and still manage to break it. For example, one guy named Mike continues to put the first half of his email in as Miek or Mik or just spelled completely wrong, and the 550 error that comes up when he puts that garbage in, which is most of the time (I think the guy is blind or something) is because his email address doesnt exist on the mail server because he cant spell it right, when on the off chance he actually does get the @domain.com in the end. I really hate my retard customers. So my simple little form blows up on them. But what I am trying to do is to have something like this if(@mail(args)) { //success, I'll call them back shortly } else { //youre a retard, please put in your email address correctly } However, the error handling isnt working. mail() is supposed to return FALSE if it encounters an error, an error that I'd rather put in an error log and not display to the customer, however, the error suppressor doesnt work. Any Suggestions? This topic has been moved to PHP Applications. http://www.phpfreaks.com/forums/index.php?topic=351056.0 I have a form where the user puts in a email address. My client whats to make sure that the emails are valid emails. So after validating the format and the domain. I will send a email to the user. I want to check to see if this email bounces or not. I think that if I add $headers .= "Return-Path: me@example.com\r\n"; to the header of the email then if it bounces an email will be sent to me@example.com. There could end up being at least 50 bounces. Is this the correct way to do this?? I have never used a Return-Path in the $headers before. It would be nice if I could put the email address that bounce into the database that the infor collected from the form goes. Hey guys. Basically i have a file containing Database connection information stored at the root of my site www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php I want to be able to connect to it using pages such as www.worldwidelighthouses.com/Lighthouses/English-Lighthouses/Beachy-Head-Lighthouse.php and www.worldwidelighthouses.com/Lightships/Lightship1.php Obviously 1 is 1 directory down, one is 2 directories down. My server doesnt allow for include 'www.worldwidelighthouses.com/Lighthouses-Database-Connection-Information.php' So whats the best way to always find this file, no matter what directory i am in? Finding out how far away i am from the server root and adding ../ to the include for each folder down was my first idea. Is this best? Thanks, Danny. Hello i m newbie to PHP. I am trying to host the website on my laptop but due to some configuration i cant send the emails through php script. I am trying send mail through mail() but not able to sent mail. heres the code: $to = "jwalant.baria@gmail.com"; $subject = "Hi!"; $body = "Hi,\n\nHow are you?"; if (mail($to, $subject, $body)) { echo("<p>Message successfully sent!</p>"); } else { echo("<p>Message delivery failed...</p>"); } Output: Message delivery failed.. I read the previous post here. but I am not able to figure out what to do about it. Can anyone tell me what setting i do in my php.ini? or any other that necessary settings require for this. i don't have SMTP server on my laptop so is there any method from which i can setup the SMTP server on laptop.? I use apache HTTP 2.2 and PHP 5.3.4 Rest of the website working correctly but only mail not working. TY..!! Hi, I am having a problem with my Website mail. Basically the mail was working fine yesterday but last night I edited the PHP script slightly because for some reason the page that it was directed to had gone missing and was turning up an 404 error, which was just a newsuince as the email was still sent. So I just edited it so that it echo'ed a message saying thanks. but is seems today the mail is not getting to its destination. The PHP returns no errors and returns the success message fine but after saying its been sent it never appears. I have tried different email addresses on different servers and that was no use and I have also changed the code back to how it was yesterday. and it still doesn't work. I have also put the page up on one of my other sites which I know everything is set up properly and it works fine, making me think that it is a mail setup issue. but as I did not set up the mail at all and quite frankly don't really understand it, I don't know how it is meant to be set up as I just use google apps for sites that I set up. So yeah I am trying to work out what could have gone wrong since yesterday but I don't really understand it, below is the code as it as now and as it was yesterday: Code: [Select] <?php $EmailFrom = "johnshale@hotmail.co.uk"; $EmailTo = "matthale.live@gmail.com"; $Subject = "Website enquiry"; $Name = Trim(stripslashes($_POST['Name'])); $Tel = Trim(stripslashes($_POST['Tel'])); $Email = Trim(stripslashes($_POST['Email'])); $Message = Trim(stripslashes($_POST['Message'])); // validation $validationOK=true; if (!$validationOK) { print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; exit; } // prepare email body text $Body = ""; $Body .= "Name: "; $Body .= $Name; $Body .= "\n"; $Body .= "Tel: "; $Body .= $Tel; $Body .= "\n"; $Body .= "Email: "; $Body .= $Email; $Body .= "\n"; $Body .= "Message: "; $Body .= $Message; $Body .= "\n"; // send email $success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>"); // redirect to success page if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">"; } else{ print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">"; } ?> and the page is at www.sullyco.co.uk/contactengine.php as you can see the page is redirecting to a page that does not exist(contactthanks.php) indicating that the message was sent successfully. it is also the part I edited as a quick fix last night I just got it to echo a success message. Thanks for any help on this, I have been trying to work it out all morning, Matt Hello, im using a contact form which sends me an email with the data name.. comments .. Now im testing a new better server which use IMAP (old POP3) and my form is not working like it used to be.. Code: [Select] $emailTo = " $dbSentEmail"; //Put your own email address here $emailServer = "noreply@totalsports.com.cy"; //Put your own email address here $body = "Name: $name \n\nEmail: $email \n\nSubject: $subject \n\nComments:\n $comments"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/plain; charset=UTF-8' . "\r\n"; $headers .= 'From: Contact Form <'.$emailServer.'>' . "\r\n" . 'Reply-To: ' . $email; mail($emailTo, $subject, $body, $headers); Any idea what i have to do to work like before? Say I have an email info@website.com created in cPanel on a web hosting company. I want to send email notifications to users on my website. I am using PHP Mailer to send the emails. But all the emails go directly into their junk box/spam folder, unless they confirm that info@website.com is not junk. I am wondering if there is a work around for this? Hi, I want to read multipart messages. If i send a mail from Gmail or yahoo, the body of the message is not read properly. I also want to read all the messages properly. Can someone give me the code for it? I am developing an email application for the first time. Thanks Raja Hi, I have Code: [Select] $to = 'rberbe2002@msn.com'; $subject = 'the subject'; $message = 'hello'; $headers = 'From: webmaster@example.com'; mail($to, $subject, $message, $headers); which works fine on a shared hosting website I have, but not on a website I have on my dedicated server. Any ideas or suggestions please? Hi, I am using the Google map API to display some businesses on a map - the sequence is map and below it a list of the establishments from a DB. Before I put the google map in, the list of establishments in the while table loop worked correctly. Now the map is there - that works, but the looping table doesnt display - I feel that it may be something to do with Code: [Select] <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> and the second fetch array - Code: [Select] while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) Any Advice? Code: [Select] <?php // *******************************below is bit that selects hotels based on outcode of postcode and prints table with links to details pages $sql2 = "SELECT * FROM hotels WHERE (SUBSTRING_INDEX(est_postcode, ' ', 1)) IN ('$matches') "; $result2 = mysql_query($sql2) or die('query failed: ' . mysql_error()); $num_rows = mysql_num_rows($result2); echo "<p> Your search has found ".$num_rows . " establishment(s) </p>"; ?> <script type="text/javascript"> var berlin = new google.maps.LatLng(<? echo $lat2 ?>, <? echo $lng2 ?>); var neighborhoods = [ <?php while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { ?> new google.maps.LatLng(<? echo $row['latitude'] ?>, <? echo $row['longitude']?>), <?php ; } ?> ]; var markers = []; var iterator = 0; var map; function initialize() { var mapOptions = { zoom: 12, mapTypeId: google.maps.MapTypeId.ROADMAP, center: berlin }; map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions); } function drop() { for (var i = 0; i < neighborhoods.length; i++) { setTimeout(function() { addMarker(); }, i * 200); } } function addMarker() { markers.push(new google.maps.Marker({ position: neighborhoods[iterator], map: map, title:"Hello World!", draggable: false, animation: google.maps.Animation.DROP })); iterator++; } </script> <div id="map_canvas" style="width: 614px; height: 400px;">map div</div> <button id="drop" onclick="drop()">Drop Markers</button> <?php echo "<table id ='results' border=0>"; while ($row = mysql_fetch_array($result2, MYSQL_ASSOC)) { echo "<tr>"; echo "<td><a class='blueboldtitle' href='bandb.php?id=". $row["id"] . "'>" . ucwords(strtolower($row["est_name"])) ."</a></td><td>" . $row["est_postcode"] ."</td><td> ". $row["est_areacode"]." ". $row["est_landline"] ."</td><td><a href='bandb.php?id=". $row["id"] . "'>[More Info] </a></td>"; echo "</tr>"; } echo "</table>"; ?> Hi, This isn't so much a problem as my code/page works however my host shut down scripting on the site as too many connections to the database were left open apparently with this page. Also ive been looking into a way of cleaning up the code and making it less bloated but the only thing I have found is mysqli for running multiple queries in one go but I am unsure if this would help. Code: [Select] <?php session_start(); include("./includes/db_con.inc.php"); $image = $_GET["id"]; $id = str_replace("-", "/", $_GET["id"]); $cat = $_GET["cat"]; $sub_cat = $_GET["sub"]; $page_title = $cat . " - " . $sub_cat . " - " . $id; $sql_meta = mysql_query("SELECT * FROM english WHERE PRODID='$id' AND display='1'"); $row_meta = mysql_fetch_assoc($sql_meta); $meta_desc = $row_meta['META_DESC']; $meta_key = $row_meta['META_KEY']; include("./includes/head.php"); include("./includes/header.php"); ?> <div id="main-page-header"> <?php $header = "img/product-pages/product-specific-headers/" . $image . ".jpg"; if (file_exists($header)) { ?> <img src="<?php echo $img_loc; ?>/product-pages/product-specific-headers/<?php echo $image; ?>.jpg" width="940" height="310" /> <?php } else { $desc_sql = mysql_query("SELECT * FROM sub_cat WHERE name='$sub_cat'"); $row_desc = mysql_fetch_assoc($desc_sql); $description = $row_desc['description']; echo "<img src='$img_loc/product-pages/sub-cat-head/".str_replace(" ", "-", $row_desc['name'])."-sub-cat-head.jpg' width='940' height='310' />"; } ?> </div> <div id="page-content"> <div id="main-page-text"> <h1><?php $result = mysql_query("SELECT * FROM $table WHERE PRODID='$id' AND display='1'"); while($row = mysql_fetch_array($result)) { $prod_title = $row['PROD_TITLE']; echo $prod_title; ?> </h1> <h2 class="crumbs"><a href="<?php echo "$url/Products/$lang/"; ?>">Products</a> > <a href="<?php echo "$url/Category/$lang/".urlencode($cat)."/"; ?>"><?php echo $cat; ?></a> > <a href="<?php echo "$url/Range/$lang/".urlencode($cat)."/".urlencode($sub_cat)."/"; ?>"><?php echo $sub_cat; ?></a> > <?php echo $prod_title; ?> </h2> <p><?php echo $row['DESCRIPTION']; } ?></p> <script src="http://connect.facebook.net/en_US/all.js#xfbml=1"></script><fb:like layout="button_count" show_faces="false" width="170" font="verdana"></fb:like> <br /> <?php $i = 1; while ($i <= 8) { $filename = "img/product-pages/hovers-800px/" . $image . "-" . $i . ".jpg"; if (file_exists($filename)) { ?> <a class="fuglybox" rel="gxr" href="<?php echo "../../../../../" . $filename; ?>"> <img src="../../../../../img/product-pages/product-detail-90px/<?php echo $image . "-" . $i . ".jpg"; ?>" alt="" width="90" height="90" /></a> <?php } else { break; } $i++; } ?> <table> <th>Product Code</th> <th>Description</th> <?php $table_result = mysql_query("SELECT * FROM PRODID WHERE PRODID='$id'"); $table_entry = mysql_fetch_assoc($table_result); echo "<tr><td class='prod-id'>" . $table_entry['PROD_CODE'] . "</td>\n"; echo "<td class='prod-desc'>" . $table_entry['TA_DESC'] . "</td></tr>\n"; ?> </table> <div id="FAQ-wrap"><h2>Frequently Asked Questions</h2> <?php $QA_table = $lang . "_qanda"; if ($id=="") { $list_QA = mysql_query("SELECT * FROM $QA_table WHERE SUB_CATEGORY='$sub_cat' AND DISPLAY='1'"); } else { $list_QA = mysql_query("SELECT * FROM $QA_table WHERE PRODID='$id' AND DISPLAY='1'"); } while($row_QA = mysql_fetch_array($list_QA)) { echo "<div id='FAQ-QA'>"; echo "<h2 class='FAQ-question'>Q: ".$row_QA['QUESTION']."</h2>"; echo "<p class='FAQ-question'>A: ".$row_QA['ANSWER']."</p></div>"; } ?> <div id="FAQ-question"> <h2 class="white">Got a question about the <span class="got-question-product"><?php echo $sub_cat; ?></span> </h2> </div> </div> </div> <div id="totem-menu-container"><?php include("./includes/search.php") ?> <?php include("./includes/totem.php") ?> </div> </div> </div> <?php include("./footer.php") ?> Please note in the db_con.inc.php is the connection to the database stored in variable $con and included in the footer.php is mysql_close($con) which is also why I dont understand how connections are being left open, any help greatly appreciated. Hi guys, I have a for loop, that queries my database, sometimes, close to 240 times, I want to minmise the DB access - what would be ideal is if I can query a result set, such as this.. Code: [Select] $result = mysql_query($sql,$con); Is it possible for me to now run a query on $result. Such as Code: [Select] select * from sometable where age >= '24' So, rather than access the DB over and over again, I just query the result set, which will be much faster. Any ideas on this one guys? Cheers Zain 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); My current code (see below) uses 147MB of virtual memory! My provider has allocated 100MB by default and the process is killed once run, causing an internal error. The code is utilising curl multi and must be able to loop with more than 150 iterations whilst still minimizing the virtual memory. The code below is only set at 150 iterations and still causes the internal server error. At 90 iterations the issue does not occur. How can I adjust my code to lower the resource use / virtual memory whilst still maintaining lightning fast speed for executing the URL and receiving the results? Alternatively, Is there an example where I am able to do overlapping HTTPS requests (rather than the below) while getting the results as they arrive. Language which supports threads to do this? Thanks! <?php function udate($format, $utimestamp = null) { if ($utimestamp === null) $utimestamp = microtime(true); $timestamp = floor($utimestamp); $milliseconds = round(($utimestamp - $timestamp) * 1000); return date(preg_replace('`(?<!\\\\)u`', $milliseconds, $format), $timestamp); } $url = 'https://www.testdomain.com/'; $curl_arr = array(); $master = curl_multi_init(); for($i=0; $i<150; $i++) { $curl_arr[$i] = curl_init(); curl_setopt($curl_arr[$i], CURLOPT_URL, $url); curl_setopt($curl_arr[$i], CURLOPT_RETURNTRANSFER, 1); curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($curl_arr[$i], CURLOPT_SSL_VERIFYPEER, FALSE); curl_multi_add_handle($master, $curl_arr[$i]); } do { curl_multi_exec($master,$running); } while($running > 0); for($i=0; $i<150; $i++) { $results = curl_multi_getcontent ($curl_arr[$i]); $results = explode("<br>", $results); echo $results[0]; echo "<br>"; echo $results[1]; echo "<br>"; echo udate('H:i:s:u'); echo "<br><br>"; usleep(100000); } ?> IS there any special code for doing this? Im not familiar with this kind of optimising
Hi to all the members of this great community, This is my first post here and I am new in PHP and in general web programming, my background is in C and C++ programming languages that's why I want to make some comments with regards to PHP and getting your feedbacks. In C++ one exercise considered that someone knows the basics of the language is to implement a general dynamic queue that is the client programmer can put an arbitrary number of objects into a queue and using templates you can instantiate different queues holding different kind of objects. I have grasped the most important parts of the language and I am pondering if you can effectively implement something like the above using PHP. I have googled this, and I have seen so far just a very simple implementation in PHP. He has defined his queue using an array having a fixed size and he just moved an index up and down through the array while inserting and poping elements from the queue. if you want to implement a dynamic queue the only way it comes to my mind just off the top of my head is to use the the construct [] to add dynamically element at the end of the queue and when you want to pop up an element you just have to unset(your current queue which is an array) create another array (smaller by one element than the previous one) copy the elements at the appropriate positions I just wanted, people with a C++ programming experience to give me some feedback about this topic and to give me some basic idea how could we implement a general queue in PHP. For example could we implement a queue w/o using an array? I would appreciate any comment. Greetings from Greece |