PHP - Delaying Sms Sending From Php Script
Hey all,
I have a simple php script that whenever it is run (it is called x times per day from crontab) it sends out an sms to 10 people. Unfortunatelly the cell carrier has put a "delay" threshold of 30 seconds between sms that you can send in order to prevent sms spamming. The problem is that my script had a foreach loop that it just send out the sms to everyone so it took around 0.5-1 second for each sms.. Way to low for the 30 seconds that now are enforced. Do you have any ideas of what i can do to "force" my script to obey that 30 second delay between each sms? I thought of putting a cron job every 1 minute and send one by one the sms but wouldn't that be a problem to the server to have to execute 1440 times per day a script? I also thought of using some sleep function but i don't know if that would result in finally the script to output a success result after 10*30=300seconds(5mins).. Any ideas are appreciated! Similar TutorialsGood day programmers, please I'm a novice in coding and I need help with a script where people can send invitation message to their friend on my site as sms. I want users on my site to just drop the phone number of their friends only in the html form and it automatically sends the message I have configured to the number the member placed in the form. I'm hosted with hostgator, though I'm in nigeria, I run SMF 2.0.1 forum on my site, my targeted members are nigerians too. I have sms gateway with bbnsms.com, please guyz I need the script and html form for only phone number field(No message Field) as I want to send the same message that I already compose to all the phone numbers. Thanks guyz. Here are the project of files: So the problem I'm running into is, while php ---> php is fine (it's recovering all of my variables, I've tested with echo), the problem seems to be where I have made a command ./createlisting.sh $itemno $title $header $description $image It reads in $itemno, $title, $header $description just fine, but it fails when I try to send an image. Again I've echoed it out and my $image variable contains the correct image name. When it gets sent to the bash script and the bash script sends it to a "log.txt" it only shows $1 thru $4, excluding the $5. When I try to use the img src to create the image on the page, the outputting echo on the page is <img src ="/images/" /> Which of course is going to result in nothing. What advice can you guys offer me? Thanks! createPage.php: <html> <body> <form enctype="multipart/form-data" action="submitForm.php" method="post"> Item#: <input type="text" name="itemno" value="1" /><br /> Title: <input type="text" name="title" value="My Listing" /><br /> Header: <input type="text" name="header" value="ENTER YOUR LISTING" /><br /> <textarea name="description" cols="60" rows="20"> You will have to use quotes on anything that has more than one word. Sorry! </textarea><br><br /></p> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose an image to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Submit" /> </form> </body> </html> submitForm.php: <?php $itemno = $_POST["itemno"]; $title = $_POST["title"]; $header = $_POST["header"]; $description = $_POST["description"]; // Where the file is going to be placed $target_path = "/home/images/"; /* Add the original filename to our target path. Result is "uploads/filename.extension" */ $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); $image = basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } $command = "." . "/" . "createlisting.sh"; $param = $itemno . " " . $title . " " . $header . " " . $description; $finalimage = $image . ""; $final = $command . " " . $param . " " . $finalimage; passthru($final); createlisting.sh: #!/bin/bash #Create the page based on the information cd logs echo $1 > log.txt echo $2 >> log.txt echo $3 >> log.txt echo $4 >> log.txt echo $5 >> log.txt cd .. ./createNewDir.sh $(date +%m%d%Y) cd .. cd listings cd $(date +%m%d%Y) mkdir $1 cd $1 echo "<HTML>" > listing.html echo "<Head>" >> listing.html echo "<Title>" >> listing.html echo "$2" >> listing.html echo "</title>" >> listing.html echo "</head>" >> listing.html echo "<body>" >> listing.html echo "<h1>$3</h1><br>" >> listing.html echo "<img src=\"/images/$5\" />" echo "$4" >> listing.html echo "</body>" >> listing.html echo "</html>" >> listing.html cd .. cd .. cd .. cd scripts echo $(date +%d%m%Y); Hi,
I have a section of code that sends an order confirmation to me when a customer places an order with us.
This all works fine but recently, I have started to get duplicate confirmations coming from the same customers, one in particular, many times a day...
Is there anything obvious about this code that could be causing it?
Thanks,
<?php Hi, I have this script, it all works fine until it gets to the message sending point. What I want is if the $registerMail variable is set to yes then send the message and redirect user to login page, if not then just redirect the user to the login page. However once registered, the user is sent to the login page and the message isnt sent. Code: [Select] <?php include_once("data/server.php"); function decode_variable(&$siteName) { $siteName = urldecode($siteName); $siteName = str_replace('%20',' ',$siteName); return $siteName; } decode_variable($siteName); $registerMail = $_GET['regMail']; $password1 = $_POST['password1']; $password2 = $_POST['password2']; // Get Posted Variables $username = $_POST['username']; $firstname = $_POST['firstname']; $lastname = $_POST['lastname']; $address = $_POST['address']; $town = $_POST['town']; $county = $_POST['county']; $postcode = $_POST['postcode']; $email = $_POST['email']; $approved = "no"; $IP = $_SERVER['REMOTE_ADDR']; if ($password1 != $password2) { echo "Your passwords did not match, please go back and register again"; } else { // MySQL Connection include_once("data/mysql.php"); $mysqlPassword = (base64_decode($mysqlpword)); $con = mysql_connect("$localhost", "$mysqlusername", "$mysqlPassword") or die(mysql_error()); mysql_select_db("$dbname", $con) or die(mysql_error()); $query = "SELECT COUNT(*) AS count FROM members WHERE username='$username'"; $results = mysql_query($query) or die ("Error reading from database"); $existingUsername = mysql_fetch_array($results); if ($existingUsername['count'] > 0) { echo "I'm sorry our database already contains that username please choose a new username to continue. "; } else { ///// Check IP address does not belong to a unapproved user $query = "SELECT COUNT(*) AS count FROM members WHERE IP='$IP' AND approved='$approved'"; $results = mysql_query($query) or die ("Error reading from database"); $bannedIP = mysql_fetch_array($results); if ($bannedIP['count'] > 0) { echo "I'm sorry your IP address has been banned from registering another account, please contact $adminEmail "; } else { $sql = "INSERT INTO members (IP, username, firstname, lastname, address, town, county, postcode, email, password, approved) VALUES ('$_SERVER[REMOTE_ADDR]','$_POST[username]','$_POST[firstname]','$_POST[lastname]','$_POST[address]','$_POST[town]','$_POST[county]','$_POST[postcode]','$_POST[email]','$_POST[password2]','$approved')"; mysql_query($sql,$con); mysql_close($con); } } } ///////////////// Send registration Mail /////////////////////////// if ($registerMail == 'yes') { $bodyReg = file_get_contents('data/registrationMail.php'); $to = "$email"; $subject = "Welcome to $siteName"; $body = "\nDear $firstname;\n$bodyReg\nUsername: $username\n Password: $password2;"; $headers = "From: $adminEmail\r\n" . "X-Mailer: php"; if (mail($to, $subject, $body, $headers)) { echo "Registration Successful. You will be redirected to login in 5 seconds."; ?> <meta http-equiv="REFRESH" content="5;url=../login.html"> <?php } } else { echo "Registration Successful. You will be redirected to login in 5 seconds."; ?> <meta http-equiv="REFRESH" content="5;url=../login.html"> <?php } ?> As always any help is much appreciated Hi All, I am attaching the code of my php script, the script needs to send mail , but is unable to do so.Your help will be greatly appreciated. Thanks Tanu Hi, i have a script problem as I am a graphic designer with zero php knowledge. I have a contact script that sends emails but they are blank. Meaning all text fields are not sending. If you could correct this for me thanks in advance. Here is my hacked up script that sends email with empty fields: im testing the following script and it wont send 1 2 3 until the script has finished executing. What can i do to flush the buffer after every echo statement?? <?php echo "1"; ob_flush();flush(); sleep(5); echo "2"; ob_flush();flush(); sleep(5); echo "3"; ob_flush();flush(); ?> Hi there, I am using this code to send the users email address to the database. That works fine, but i keep getting blank info added to the database. Does anyone know how i can stop this? <?php $con = mysql_connect("*","*","*"); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db("ogs_mailinglist1", $con); $sql="INSERT INTO mailinglist (email) VALUES ('$_POST[rec_email]')"; if (!mysql_query($sql,$con)) { die('Error: ' . mysql_error()); } mysql_close($con); ?> Thanks, Hi, I am trying to loop a script every 10 seconds but am getting the following error: Fatal error: Maximum execution time of 60 seconds exceeded Part of the code is: <?php while (1) { echo "hello"; sleep(10); ob_flush; flush(); } ?> I have put echo "hello" just to test before adding the script. Is there a correct way to do this loop? also running this the page struggles and says it is still loading. From our website we are connecting to GMAIL to send our emails through SMTP. For some reason it is not sending the emails to the CC or BCC email address event though GMAIL shows it was included in the email. Am I missing something in the below code? Code: [Select] $currentTime = time(); $emailTo = "redbrad0@domain.com"; $emailCC = "brad@domain.com"; $emailBCC = "events@domain.com"; $emailSubject = "TEST Email at (" . $currentTime . ")"; $emailBody = "This is the body of the email"; $headers = array(); if (!empty($emailTo)) $headers['TO'] = $emailTo; if (!empty($emailCC)) $headers['CC'] = $emailCC; if (!empty($emailBCC)) $headers['BCC'] = $emailBCC; if (!empty($emailSubject)) $headers['Subject'] = $emailSubject; $headers['From'] = "events@domain.com"; $mime = new Mail_mime("\n"); $mime->setTXTBody($emailBody); $body = $mime->get(); $headers = $mime->headers($headers); $mail = Mail::factory('smtp', array ('host' => 'ssl://smtp.gmail.com', 'auth' => true, 'port' => 465, 'username' => 'events@domain.com', 'password' => 'thepasswordhere')); try { $result = $mail->send($emailTo, $headers, $emailBody); } catch (TixException $ex) { echo "<font color=red>Error:" . $ex->getCode() . "</font><br>"; } echo "Emailed at (" . $currentTime . ")<br>"; die; Code: [Select] $sql="SELECT * FROM $tbl_name3 WHERE review_show='n'"; $result=mysql_query($sql); $num_results=mysql_num_rows($result); if($num_results > 1){ $message="You have ".$num_results." reviews unapproved."; mail('example@example.com','GHP Reviews', $message, 'From: example@example.com'); } $sql2="SELECT * FROM $tbl_name4 WHERE rma_issued='n'"; $result2=mysql_query($sql2); $num_results2=mysql_num_rows($result2); if($num_results2 > 1){ $message="You have ".$num_results2." RMA Numbers Requested."; mail('example@example.com','GHP RMA Number Requests', $message, 'From: example@example.com'); } The reviews email is being sent, however, the RMA email is not. EDIT: Nevermind, $num_results and $num_results2 should have been > 0 not > 1. Hi, I hope it is possible to establish, what I am going to ask Currently I am using a site where I am entering a xml code, that is sent to certain workflow. That workflow returns me a few csv files within the same http session. So simply, there is a page with the TEXTAREA - where i enter xml code and subsequently I click on the Submit button. After that the new page is opened where I have links to csv files. I wonder if would be possible to establish that using php code. I would like to run everything in background, sending xml code to that workflow and get those files. Everything without opening that site, entering xml code, submitin that ,and clicking on each link to download those files. I am not looking for exact answer. Just if you can tell me where I can start. My php knowledge is not great, but I have written a few things so far. So if you can help where to start, I would be more than happy Thanks Hey guys, Coding something for a survey as no solution exists for our needs. I have not finished the code as I still need to do error checks + making it spam proof. Anyway I am not reciving the email even though it says that I have been sent it. Any suggestions are appreciated, please ask if you need additional info to be able to help, and thank you in advanced. Code: [Select] <?php error_reporting(0); if(isset($_POST['submit'])){ //Check that all fields that are mandatory are filled in and that the $Email variable is real $Title = $_POST['Title']; $FirstName = $_POST['FirstName']; $LastName = $_POST['LastName']; $Email= $_POST['Email']; $Country= $_POST['Country']; $State= $_POST['State']; $List= $_POST['List']; $Nav= $_POST['Nav']; $IssuesYes= $_POST['IssuesCheck']; $IssuesList= $_POST['IssuesList']; $Satisfaction= $_POST['Satisfaction']; $Improvement= $_POST['Improvement']; $ValueSatisfaction= $_POST['Value']; $Recommendation= $_POST['Recommend']; $Knowledge= $_POST['Knowledge']; $Comments= $_POST['Comments']; $Gender= $_POST['Gender']; $Age= $_POST['Age']; $Source= $_POST['Source']; $ContactNumber= $_POST['Contact']; $Newsletter= $_POST['Newsletter']; $errors = array(); //Check that the fields above are not empty: $to = "email@email.com";//Obviously not real one that I am sending to. $subject = "Survey Form Submission"; $from = $to; $ip = isset($_SERVER['REMOTE_ADDR']) ? $_SERVER['REMOTE_ADDR'] : ''; $body = "$name submitted the survey form:\n". "This is what they responded with to each question: <br>". "Their Name: $Title $FirstName $LastName <br>"."Email: $Email <br>"."Country: $Country <br>"."State: $State<br>"."Bought: $List<br>"."Website Navigation: $Nav<br>"."Issues: $IssuesYes " ." $IssuesList"."Satisfaction: $Satisfaction<br>"."Improvement: $Improvement<br>"."Value Satisfaction: $ValueSatisfaction<br>"."Reccomend: $Recommendation<br>"."Knowledge: $Knowledge<br>"."Comments: $Comments <br>"."Gender: $Gender<br>"."Age: $Age <br>"."Source for Finding Us: $Source <br>"."Contact: $ContactNumber<br>"."Subscribe to Newsletter?: $Newsletter<br>"; $headers = "From: $from \r\n"; $headers .= "Reply-To: $visitor_email \r\n"; if( mail($to, $subject, $body,$headers)){ echo "Email Send!"; }else{ echo "Somethings wrong :\ "; } // header('Location: http://www.********/thank-you-for-survey'); } ?> this is my email.php file <?php $senderName =$_POST['userName']; $senderEmail =$_POST['userEmail.']; $senderMessage =$_POST['userMessage.']; //security $senderName=stripslashes($userName); $senderEmail=stripslashes($userEmail); $senderMsg=stripslashes($userMessage); $to = 'myName@mydomain.com'; $from = 'myName@mydomain.com'; $subject = 'Testing CONTACT PAGE'; $message = 'Message From your site: Their Name: $senderName Their Email: $senderEmail Their Message is below: $senderMsg'; // Build $headers Variable $headers = 'From: Company <mysite@mydomain.com.com>' . "\r\n"; $to = '$to'; // Send the email mail($to, $subject, $message, $headers); $my_msg='thanks your message has been sent.'; print $my_msg; ?> The error I'm getting is this: Parse error: syntax error, unexpected T_ENCAPSED_AND_WHITESPACE, expecting T_STRING or T_VARIABLE or T_NUM_STRING in C:\xampp\htdocs\PHP_Test\email.php on line 5 all I want to be able to do is verify my form works and that I can receive emails from users of mysite any help would be greatly appreciated. Also what should the send_mail in the PHP.INI file be set to? thansk Hi Guys I am creating a site which allows the registration of new users. I already have my user registration page up and running which is lnked to my database. I would now like to add a function which will send a 'welcome to...' email to the email address provided on the registration form provided by the new user. Could anybody please point me in the right direction i.e where to start? I am using dreamweaver and Cpanel. Thanksin advance Hi, I want to send an email to my registered users so that when they click on the URL given in the message hey should come back to my site as confirmetion of their registration. I am able to send the mail but the mail body is not coming as expected. Here's my code Code: [Select] <?php public function email($id){ //get users info $this->userInfo = $this->model->listUser($id); $this->sendEmail($this->userInfo); } public function sendEmail($data){ $to =$data['email']; $this->msg ="<img src=\"ideas.kpjit.com/public/images/header-img.jpg\" /> <h1>KPJ Idea</h1> <p>Make a difference</p> <p>This is a Confirmation Mail.Please confirm your registration by clicking here <a href=\"http://ideas.kpjit.com\register\confirm\ <?php echo $this->data['id'];?></p>\" "; $subject = "Registration confirmation"; $message = $this->msg; $from ="narjisfatima@yahoo.com"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers = 'MIME-Version: 1.0' . "\r\n"; $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n"; $headers .= 'From:narjisfatima@yahoo.com' . "\r\n"; if(mail($to,$subject,$headers)){ $this->render2("register/message"); exit; } } Also I am unable to insert my site banner in the mail. How can I do It. I am creating a forgotten password button, it works but it just doesn't send me an email containing the reset link.
Here's the code for the email part:
<?php require("../config.php"); if($_GET['code']) { $get_username = $_GET['username']; $get_code = $_GET['code']; $query = mysql_query("SELECT * FROM users WHERE username='$get_username'"); while($row = mysql_fetch_assoc($query)) { $db_code = $row['passreset']; $db_username = $row['username']; } if($get_username == $db_username && $get_code == $db_code) { echo " <form action='pass_reset_complete.php?code=$get_code' method='POST'> Enter a new password<br><input type='password' name='newpass'><br> Re-enter your password<br><input type='password' name='newpass1'><p> <input type='hidden' name='username' value='$db_username'> <input type='submit' value='Update Password!'> </form> "; } } if(!$_GET['code']) { echo " <form action='forgot_pass.php' method='POST'> Enter your username<br><input type='text' name='username'><p> Enter your email<br><input type='text' name='email'><p> <input type='submit' value='Submit' name='submit'> </form> "; if(isset($_POST['submit'])) { $username = $_POST['username']; $email = $_POST['email']; $query = mysql_query("SELECT * FROM users WHERE username='$username'"); $numrow = mysql_num_rows($query); if($numrow!=0) { while($row = mysql_fetch_assoc($query)) { $db_email = $row['email']; } if($email == $db_email) { $code = rand(10000,1000000); $to = $db_email; $subject = "Password Reset"; $body = " This is an automated email. Please DO NOT reply to this email. Click the link below or paste it into your browser http:/www.***REMOVED***.com/second/forgot_pass.php?code=$code&username=$username "; mysql_query("UPDATE users SET passreset='$code' WHERE username='$username'"); mail($to,$subject,$body); echo "Check Your Email"; } else { echo "Email is incorrect"; } } else { echo "That username doesnt exist"; } } } ?> I need some help over here. I want to send an email to my friends by checking the database and extract the id. After extracting the id from the database, i want to include a URL with the id. E.g. www.abc.php?35 (35 is the id) www.abc.php?40 (40 is the id) May I know how to send an email with multiple url? Is it using a for loop in the php email function? Your help is greatly appreciated. Hi
I have below code :
<?php $_SERVER['SERVER_NAME']; $to = "info@domain.com"; $subject = "Test mail"; $body = $_SERVER['SERVER_NAME']; $from = "user@example.com"; $headers = "From:" . $from; mail($to, $subject, $body, $headers) ?>the email is sent correctly but without any body text . I use $_SERVER['SERVER_NAME']; but nothing show as body . I want to use this code load each day becuse I want to know which domain is used my script. but now the code not work. Hi
I am trying to use mail(), but when I try it i am not receiving the email. Code is as follows
$username=$_POST['username']; $email=$_POST['email']; $password=$_POST['password']; //email user $from='registrations@ispeedwayscores.com'; $to=$email; $subject='Thank you for registering at iSpeedwayScores'; $message ='<html> <body bgcolor="#000000" style="color:#FF9900; font:Verdana, Arial, Helvetica, sans-serif"> <center> <h1>Welcome to iSpeedwayScores</h1> <br/> <p>Hi!</p> <br> <p>Thank you for joining iSpeedwayScores, this is your <b>FREE</b> online speedway scorecard site.</p> <p>Your login details are provided below:</p> Username: '.$username.'<br/> Password: '.$password.'<br/> <p>We hope you enjoy using the site, if you do, please tell others, if not please tell us</p> <h3>iSpeedwayScores</h3> </body> </html>'; //end of message $headers = "From: $from\r\n"; $headers .= "Content-type: text/html\r\n"; //options to send to cc+bcc $headers .= "Bcc: mark@bravo14.co.uk"; // now lets send the email. if(mail($to, $subject, $message, $headers)){ $message=" Message sent successfully"; $regsuccess = "Message sent successfully"; } else{ $message=" Message not sent"; $regfailure ="Message not sent"; } |