PHP - Cronjob And Imap Is Not Working When Disable Email
I have a script that fetch emails and its work file when I call it through SSH with PHP at the beginning on the path
when I added a cronjob it was working fine too... the problem start when I disable the cronjob email response, the script dose not functioning with Imap What can I do in order to bypass this problem, I will try to call it with include but I have no other options.. Please help Similar TutorialsMy host has a limit of 100 emails per hour and this is now being reached to many times a day and some emails are not being sent due to this. Does anyone have a script or know of one that can stack emails to be sent in MySql or something and every 5 minutes send one out from the stack and then delete from the stack the ones sent. Hi guys, I have written a script that opens up my gmail messages via IMAP stores them in an array. However, I have thousands of emails, so this is taking forever. Is there a faster way of doing this? Here's my code Code: [Select] <?php //lets get those emails /* connect to gmail */ $hostname = '{imap.gmail.com:993/imap/ssl}INBOX'; $username = 'info@***********.com'; $password = '******'; /* try to connect */ $inbox = imap_open($hostname,$username,$password) or die('Cannot connect to Gmail: ' . imap_last_error()); /* grab emails */ $emails = imap_search($inbox,'ALL'); /* if emails are returned, cycle through each... */ if($emails) { /* for every email... */ foreach($emails as $email_number) { $message = imap_fetchbody($inbox,$email_number,2); } } /* close the connection */ imap_close($inbox); ?> I have spent nearly all day scouring Google for help on this and after trying numerous scripts unsuccessfully and reading up on imap functions but still getting nowhere as well as frying my brain l have had to accept defeat unless anyone of the many gifted coders here can help me out with a script they might have written and used. many thanks Callum Hi, cd /var/www/html/googleplaystore-root-folder && php artisan schedule:run >> /dev/null 2>&1 This is the code developer gave me to add to the cronjob. and the location of my script is /home/vvkpexpj/public_html/example.com
Do i need to make any changes to the cronjob code he given.? i had copy pasted the code same as what he gave, but its not working Don't have a huge deal of experience with this side of things, well php as a whole really but really struggle with this side, ive coded up a cron but it only works for 1 user, unsure as to why, i want it to do the action for every player that has item 17, the codes below any help would be appreciated, Thanks guys Code: [Select] <?php include("server.php"); $sql = "SELECT * FROM player_inventory WHERE item_id = 17"; $que = mysql_query($sql) or die(mysql_error()); $res = mysql_fetch_array($que); $sql2 = "SELECT * FROM players WHERE id = $res[player_id]"; $que2 = mysql_query($sql2); while($res2=mysql_fetch_array($que2)) { $Weight = 8 / 100 * (100 + $res2['ProductionWeight']); $Quality = 75 / 100 * (100 + $res2['ProductionWeight']); $StreetCred = $Weight * $Quality / 10; $update = "UPDATE players SET StreetCred = StreetCred + $StreetCred WHERE id = $res[player_id]"; mysql_query($update) or die(mysql_error());; $update2 = "INSERT INTO drug_inventory (player_id,quality,weight) VALUES('$res[player_id]',$Quality,$Weight)"; mysql_query($update2) or die(mysql_error());; echo "Grow Completed."; } ?> Ok, So I have a php script which I want to call using a cron job... It all works correctally when I call it from a browser, and I have updated the local paths to include the full url. All the local side of things works correctally/ fine. The issue is that during part of the script I am pulling an image from an external source (specifically Apple). I'm then using ImageMagik to convert it to a png and save the file locally. Again this all works outside of using a cron job, but dosen't when I am using a cron job... It's either an issue with the fact I'm using an external link, or an issue with utilizing ImageMagik... If it's a ImageMagik issue then I'll ask on their forums - but I first wanted to check there shouldn't be any issues with using external links in a php triggered by cron? Like it dosent try find the file at /usr/www/users/<external link here> or anything dumb like that? Cheers, - Adam G Hi, I am using cpanel, where i am want to run a php file, to delete the old records, i used cronjob in cpanel to do this. In time columns i have made : * * * * * to execute each and every minute the script.. In the command textbox i have made: /home/server25/public_html/auto_cancel.php in the email box: admin_email@gmail.com I am getting Permission denied to my email address: The error report am getting is : /bin/sh: /home/server25/public_html/auto_cancel.php: Permission denied Please help me to solve this. Thanks, Hi there,
I want to make script which will execute via crontab every Sunday at 0:01h and will stop at 23:59h. My goal is to put(show) some tekst on the site. The problem is how to put this tekst in the site? I mean I know how to configure Cron Jobs but how to include the tekst in index.php for example?
crontab will be.
1 0 * * 0 /usr/bin/php Start.php 59 23 * * 0 /usr/bin/php Stop.php Hi all I'm trying to send an automated email of a zip file. However it seems to be just reading the files into the body of the mail rather than attaching a single zip archive containing several files. I receive the mails, but I effectively want a blank message body with a zip file attached. Please see code below, any ideas why this is not working. I'm a bit of a newbie and never used this before so any pointers would be good. <?php //Send Zip file as attachment //Set Email and attachment details $to = "me@123.com"; $from = "Visionnet <DO_NOT_REPLY>"; $subject = "Subject"; $message = "Please see attached file"; $fileatt = "wiki_zip.zip"; $fileatt_type = "application/zip"; $fileatt_name = "wiki_zip.zip"; //Read in the attachment $file=fopen($fileatt,'rb'); $data=fread($file,filesize( $fileatt)); fclose($file); //Add the MIME content $semi_rand = md5(time()); $mime_boundary = "==Multipart_Boundary_x{$semi_rand}x"; // Add the Headers for file attachment $headers .= "\nMIME-Version: 1.0\n" . "Content-Type: multipart/mixed;\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multipart message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; //Base64 encode file data $data = chunk_split(base64_encode($data)); //Add attachment to message $message .= "--{mime_boundary}\n" . "Content-Type: {$fileatt_type};\n" . " name=\"{$fileatt_name}\"\n" . "Content-Disposition: attachment;\n" . " filename=\"{$fileatt_name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; //Send message $ok = @mail($to, $subject, $message, $headers, "$from"); if($ok) { echo "mail sent"; } else { echo "mail failed"; } ?> Hi all, I'm trying to add a section where it verifies that the email address is active in my register code. My code below is it checking the dnsrr, and if it is not real, I have it die and an error message appears. However, I am getting the error message all the time, whether I am sure the email is working or not. First I declared my email variable ($email), and then after the code below I of course insert the new data in to the database. I'm doing this over my localhost, so is that why it can't verify emails? Or am I setting this up wrong? Code: [Select] <?php $email = trim($_POST['email']); if (False !== strpos($email, '@')) die("Please type in an email address.<br><br><a href=register.php>Continue</a>"); if(!@checkdnsrr($mailDomain,'MX')) die("Not real email address. Please try again.<br><br> <a href=register.php>Continue</a>"); ?> For some reason my email system isnt working, but no errors are showing up and i cant seem to find a syntax error. I need some fresh eyes to help to solve this... Code: [Select] <?php if(isset($_POST['PersonName'])) { // EDIT THE 2 LINES BELOW AS REQUIRED $email_to = "j.hopley@2008.ljmu.ac.uk"; $email_subject = "An email from your blog."; function died($error) { // your error code can go here echo "We are very sorry, but there were error(s) found with the form you submitted. "; echo "These errors appear below.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['PersonName']) || !isset($_POST['PersomComment']) || !isset($_POST['PersonEmail']) || !isset($_POST['PersonNumber'])) { died('We are sorry, but there appears to be a problem with the form you submitted. One or more fields were empty or contained invailid charicters.'); } $person_name = $_POST['PersonName']; // required $person_comment = $_POST['PersomComment']; // required $person_email = $_POST['PersonEmail']; // required $person_number = $_POST['PersonNumber']; // not required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$person_email)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$person_name)) { $error_message .= 'The Name you entered does not appear to be valid.<br />'; } if(strlen($person_comment) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.<br />'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "First Name: ".clean_string($person_name)."\n"; $email_message .= "Email: ".clean_string($person_email)."\n"; $email_message .= "Telephone: ".clean_string($person_number)."\n"; $email_message .= "Comments: ".clean_string($person_comment)."\n"; // create email headers $headers = 'From: '.$person_email."\r\n". 'Reply-To: '.$person_email."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); } ?> hi need some help, the following PHP script on my website has stopped working without me editing it : <?php if(isset($_POST['email'])) { // CHANGE THE TWO LINES BELOW $email_to = "contact@myemail.com"; $email_subject = "enquiry"; function died($error) { // your error code can go here echo "Sorry, but errors were found in the form you submitted.<br /><br />"; echo $error."<br /><br />"; echo "Please go back and fix these errors.<br /><br />"; die(); } // validation expected data exists if(!isset($_POST['full_name']) || !isset($_POST['email']) || !isset($_POST['telephone']) || !isset($_POST['comments'])) { died('We are sorry, but there appears to be a problem with the form you submitted.'); } $first_name = $_POST['full_name']; // required $email_from = $_POST['email']; // required $telephone = $_POST['telephone']; // not required $comments = $_POST['comments']; // required $error_message = ""; $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/'; if(!preg_match($email_exp,$email_from)) { $error_message .= 'The Email Address you entered does not appear to be valid.<br /><br />'; } $string_exp = "/^[A-Za-z .'-]+$/"; if(!preg_match($string_exp,$first_name)) { $error_message .= 'The Full Name you entered does not appear to be valid.<br /><br />'; } if(strlen($comments) < 2) { $error_message .= 'The Comments you entered do not appear to be valid.'; } if(strlen($error_message) > 0) { died($error_message); } $email_message = "Form details below.\n\n"; function clean_string($string) { $bad = array("content-type","bcc:","to:","cc:","href"); return str_replace($bad,"",$string); } $email_message .= "Full Name: ".clean_string($first_name)."\n"; $email_message .= "Email: ".clean_string($email_from)."\n"; $email_message .= "Telephone: ".clean_string($telephone)."\n"; $email_message .= "Comments: ".clean_string($comments)."\n"; // create email headers $headers = 'From: '.$email_from."\r\n". 'Reply-To: '.$email_from."\r\n" . 'X-Mailer: PHP/' . phpversion(); @mail($email_to, $email_subject, $email_message, $headers); ?> <!-- place your own success html below --> Thank you for contacting us, we will be in touch soon. <?php } die(); ?> which was working with the following form: <form name="htmlform" method="post" action="contact_uk.php"> <table style="background-color:whitesmoke; border:1px solid black; border-collapse:collapse" ;="" width="542px"> <tbody><tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="first_name">Full Name *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="full_name" maxlength="50" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="email">Email Address *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="email" maxlength="80" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="top"> <label for="telephone">Telephone Number</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <input name="telephone" maxlength="30" size="30" type="text"> </td> </tr> <tr> <td style="border:1px solid black; text-align:center; font-family:calibri" valign="middle"> <label for="comments">Message *</label> </td> <td style="border:1px solid black; text-align:center" valign="top"> <textarea name="comments" maxlength="1000" cols="22" rows="6"></textarea> </td> </tr> <tr> <td colspan="2" style="text-align:center"> <input value="Submit" type="submit"> </td> </tr> </tbody></table> </form> Now, I have tried the following test script found here (http://myphpform.com...not-working.php) and it does not work : <?php $from = "contact@myemail.com"; $headers = "From:" . $from; echo mail ("admin@awardspace.com" ,"testmailfunction" , "Oj",$headers); ?> so I have then contacted my Host which replied as follows: when you send emails by scripts and it is that our SMTP server requires authentication in order to send emails out. By using one of the emails that exist in the control panel as a sender/"from" header, you will be able to authenticate yourself and the SMTP server will send without problems. and provided this script, which works: <? $from = "From: You <contact@myemail.com>"; $to = "anymail@hotmail.com"; $subject = "Hi2! "; $body = "TEST"; if(mail($to,$subject,$body,$from)) echo "MAIL - OK"; else echo "MAIL FAILED"; ?> so can someone help me fix the code in the first quote I posted based on this last working one ? A few things maybe worth a mention: - previously, about a few weeks back, this form (first two quotes) was working perfectly as I've posted it and sending emails to my hotmail account without a hitch... - in the quotes "contact@myemail.com" is actually the domain email I have with the host thanks to anyone kind enough to help out... :'(I've already had two strikes on my efforts at questions, so I'm planning on at least fouling this one away.... The attached, running(!) PHP email generating program allows me to input info, but then generates the following error message after filling out the form: from Yahoo website: "Sorry, the page you requested was not found. "Additionally, a 410 Gone error was encountered while trying to handle the request." Here is the questionable code: <html> <body> <?php if (isset($_REQUEST['email'])) //if "email" is filled out, send email { //send email $email = $_REQUEST['email'] ; $subject = $_REQUEST['subject'] ; $message = $_REQUEST['message'] ; mail( "debbiekn777@yahoo.com", "Subject: $subject", $message, "From: $email" ); echo "Thank you for using our mail form"; } else //if "email" is not filled out, display the form { echo "<form method='post' action='mailform.php'> Email: <input name='email' type='text' /><br /> Subject: <input name='subject' type='text' /><br /> Message:<br /> <textarea name='message' rows='15' cols='40'> </textarea><br /> <input type='submit' /> </form>"; } ?> </body> </html> Please, where do I go from here? Trying to be different from the last kid, Yshua i have a form for sending email with cc and bcc bud when try to send it.. it shows an error..
please see it here
http://www.pstwist.com/send-cc-email/
Attached Files
123.zip 2.28KB
0 downloads What am I doing wrong? All I want is a flash and php email form working. At best i get the elements emailed surrounded by all the html formatiing tags makign it impossible to head or only a few (ie messahe and phone) show up in email sent or more often nothign gets sent at all. In the flash filn I have a send button with Code: [Select] onClipEvent(data){ _root.nextFrame(); } actioned on the form movie in flash And Code: [Select] on(release){ form.loadVariables("email_send.php", "POST"); } script on the send button. The movie where the form is places has 5 fields made with input text with Instant names: Inp_Name Inp_Department Inp_Email Inp_Phone Inp_Message their variables are; name dept phone message Also in the properties theya re all set to HTML rednering is set to off and the webssite is www.chriscreativity.com Why does it not work at all and if it does how do I loose the htmal formings crap and get it to work please Code: [Select] <strong><?php /* --------------------------- php and flash contact form. by www.MacromediaHelp.com --------------------------- Note: most servers require that one of the emails (sender or receiver) to be an email hosted by same server, so make sure your email (on last line of this file) is one hosted on same server. --------------------------- */ $sendTo = "chris.bruneluni@yahoo.co.uk"; $subject = "Message from chriscreativity.com"; // read the variables form the string, (this is not needed with some servers). $headers = $_POST["name"] . $_POST["dept"] . $_POST["email"] . $_POST["phone"]; $message = $_POST["message"]; mail($sendTo, $subject, $message, $headers); ?></strong> [attachment deleted by admin] <form action="form-to-email.php" method="post" enctype="text/plain" class="form"> <p class="name"> <i class="icon-user"></i> <input type="text" name="name" id="name" /> <label for="name">Name</label> </p> <p class="email"> <i class="icon-envelope"></i><span id="sprytextfield1"> <input type="text" name="email" id="email" /> </span> <label for="email">E-mail</label> </p> <p class="phone"><i class="icon-phone-sign"></i> <input type="text" name="phone" id="phone" /> <label for="web">Phone</label> </p> <p class="text"><span id="sprytextarea1"> <textarea name="text"></textarea> <span class="textareaRequiredMsg">A value is required.</span></span></p> <p class="submit"> <input type="submit" name="submit" id="submit" value="Send message"> </p> </form>The form is located in index.html and separate page is form-to-email.php. Do I need to link them <link href=>, <link rel=> or the files just need to be in the same folder? <?php if(!isset($_POST['submit'])) { //This page should not be accessed directly. Need to submit the form. echo "error; you need to submit the form!"; } $name = $_POST['name']; $visitor_email = $_POST['email']; $message = $_POST['message']; //Validate first if(empty($name)||empty($visitor_email)) { echo "Name and email are mandatory!"; exit; } if(IsInjected($visitor_email)) { echo "Bad email value!"; exit; } $email_from = '$visitor_email \r\n"'; $email_subject = "New Form submission"; $email_body = "You have received a new message from the user $name.\n". "Here is the message:\n $message". $to = "2d2f@gmail.com";//<== update the email address $headers = "From: $email_from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; //Send the email! mail($to,$email_subject,$email_body,$headers); //done. redirect to thank-you page. header('Location: thank-you.html'); I've created a script to remove duplicate emails and it works perfectly up to about 20k. After that it just stops with no error code. I'm baffled. I've increased the max_execution_time to 2 hours even though this script just takes a few minutes. <?PHP function validElement($element) { return strlen($element) > 1; } function in_iarray($str, $a){ foreach($a as $v){ if(strcasecmp($str, $v)==0){return true;} } return false; } remove_duplicates(); } //Remove more duplicates from list function array_iunique($a){ $n = array(); foreach($a as $k=>$v){ if(!in_iarray($v, $n)){ echo $v; $n[$k]=$v;} } return $n; } //Remove duplicates from list function remove_duplicates() { $p = 0; while ($p != 1) { $rawemaillist = array_values(array_filter($rawemaillist, "validElement")); $p = 1; } $initial = count($rawemaillist); $k = 0; while ($k != 1) { $rawemaillist = array_iunique($rawemaillist); $k = 1; } ?> The script works fine - but only up to around 20 k - which leads me to believe its a server setting issue. Is there something in the php.ini file I should or otherwise a setting that I should be looking at to change??? This is completely different code than my change password script thread. This is not double posting. Whenever I use this script to change my email, it just changes the email to nothing (blank). What could be wrong with it? Help is hugely appreciated. I know you don't have to use your valuable time to help me. <?php // I removed the connect to db part session_start(); $username = $_SESSION['username']; $email = $_POST['email']; $newemail = $_POST['newemail']; $confirmnewemail = $_POST['confirmnewemail']; $result = mysql_query("SELECT email FROM members WHERE username='$username'"); if($email!= mysql_result($result, 0)) { echo "The email address you entered is incorrect."; } if($newemail==$confirmnewemail) $sql=mysql_query("UPDATE members SET email='$newemail' where username='$username'"); if($sql) { echo "You have successfully changed your email address."; } else { echo "The new email and confirm new email fields were different."; } ?> I'm using imap_open and when I use imap_headerinfo and output the info, I want to be able to have an array of words to match the fromaddress to.... case-insensitive. I tried ton of different ways... array_search array_filter stripos stristr And tried adding strtolower in a few Tried setting the object as a var and comparing it that way... but it either chokes on the object or the array... Or ignores it completely For example setting an array like this: Code: [Select] $blacklist_array = array("wl_partners@cupid.com", "Replica Shop", "CJ Adams", "eharmony", "Dr.Maxman", "Credit Check"); And the fromaddress has this in it: Credit Check <check@iamaspammer.com> I can't get it to work to match the Credit Check only part. I got it to work if I do a foreach through the messages and then a foreach through the array then process a good or bad result, but it takes too long if there are a ton of messages to process... The code is a mess right now with all the trial and errors. Any ideas? I'm kinda brain dead at this point and have been up way to long... Thanks... Hey guys, Been developing a bespoke "helpdesk" system for work and, while it works well on the whole, I am having major problems with base64 encoded email bodies. Admittedly, this might be due to my misunderstanding of imap body parts. It seems in my current setup, the system thinks that all mails are either "type" 0 or 4. As a result, base64 emails don't get decoded and display as an unreadable long string. Here is what my code for the body decoding looks like just now - can provide more on request. $from=$overview[0]->from; $subject=$overview[0]->subject; $subdb=mysql_real_escape_string($subject); $lookingfor=explode("~#",$body); $result=$from; $find=strrpos($ir, $lookingfor[1]); $findreplystream=mysql_query("SELECT * FROM tickets WHERE ticket_md5='$lookingfor[1]'") or die(''.mysql_error().''); $stream=mysql_fetch_array($findreplystream); $now=time(); if($structure->encoding == 0){ $arr1=array("=A3", "=80"); $arr2=array("£", "€"); $newcontent=$explodeunder[0]; define("CHARSET", "ISO-8859-1"); $dbcontenta=str_replace($arr1, $arr2, $newcontent); $r=mb_detect_encoding($dbcontenta); if($r=="UTF-8"){ $dbcontents=mb_convert_encoding($dbcontenta, "ISO-8859-1", "UTF-8"); $dbcontent1=addslashes($dbcontents); $dbcontent2=strip_tags($dbcontent1); } elseif($r=="ASCII"){ $dbcontentb=mb_convert_encoding($dbcontenta, "UTF-8", "ASCII"); $dbcontents=mb_convert_encoding($dbcontentb, "ISO-8859-1", "UTF-8"); $dbcontent1=addslashes($dbcontents); $dbcontentf=strip_tags($dbcontent1); $dbcontent2=quoted_printable_decode($dbcontentf); } } elseif($structure->encoding == 4) { $dbcontent=$explodeunder[0]; $dbcontentf=quoted_printable_decode($dbcontent); $dbcontent2=mb_convert_encoding($dbcontentf, "ISO-8859-1", "UTF-8"); } elseif($structure->encoding == 3) { $dbcontent2=imap_base64($explodeunder[0]); } elseif($structure->encoding == 1){ $dbcontent3=imap_8bit($explodeunder[0]); $dbcontent2=quoted_printable_decode($dbcontent3); } Can anyone advise me with this? I'd be greatful for any assistance at all, as it's causing me nightmares! All the best |