kevinkhan Posted January 30, 2010 Share Posted January 30, 2010 Hi everyone.. I have a php script that works perfect $to = "[email protected]"; $subject = "Dublin Texting Starting At: ".date('Y-m-d H:i:s'); $body = "Starting at: ".date('Y-m-d H:i:s'); mail($to, $subject, $body); unset($body); $body = "testing 123 \n"; $body .= "No phone numbers found to be sent messages.\n"; $to = "[email protected]"; $subject = "Dublin Texting Finished At: ".date('Y-m-d H:i:s'); mail($to, $subject, $body); I build up a string using .= and mail the whole string at the end of the script.. Now im trying to do the exact same thing with another script but is not working at all i dont know what the problem is.. I want to run the script and mail the $body variable at the end of the script.. Please have a look and see if you can tell me the problem Thanks #!/usr/local/bin/php <?php // echo time of beginning $to = "[email protected]"; $subject = "Dublin Texting Starting At: ".date('Y-m-d H:i:s'); $body = "Starting at: ".date('Y-m-d H:i:s'); mail($to, $subject, $body); unset($body); require_once('/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/mysql.php'); $obj = new db(); set_time_limit(0); // report errores error_reporting(E_ERROR | E_WARNING | E_PARSE); // accounts must be put in this file $source_file = '/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/accounts.txt'; // message must be put in this file $message_file = '/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/message.txt'; $fp = fopen($message_file, 'r'); $message = fread($fp, filesize($message_file)); fclose($fp); $fp_s = fopen($source_file, 'r'); $ch = curl_init(); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true); curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 5.1; .NET CLR 1.1.4322)'); //curl_setopt($ch, CURLOPT_PROXY, '200.174.85.193:3128'); // save cookie curl_setopt($ch, CURLOPT_COOKIEJAR, '/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/cookie.txt'); // get cookie curl_setopt($ch, CURLOPT_COOKIEFILE, '/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/cookie.txt'); // not to print out the results curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // // get the list of phone number which will be sent messages // $sql = 'select phone from phone_number where phone not in (select phone from phone_number_sent)'; $obj->executesql($sql); $phone_list = $obj->fetch_array(); if (count($phone_list)>0) { $body = "\n", count($phone_list), " PHONE AVAILABLE.\n"; $body .= 'Message lenght (should be less than 160) is: ', strlen($message), "\n"; $body .= "Message is: $message\n\n"; $num_sent = 0; // search for a account which haven't reached the limitation while (($data = fgetcsv($fp_s, 32)) !== FALSE and $num_sent < count($phone_list)) { $array_data = explode(':', $data[0]); $account = trim($array_data[0]); $password = trim($array_data[1]); $body .= 'Account: ', $account, ", "; // // Log in // // set URL $url = 'https://www.mymeteor.ie/go/mymeteor-login-manager'; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); unset($post_data); $post_data['msisdn'] = $account; $post_data['pin'] = $password; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // execute request $text = curl_exec($ch); //echo $text; //print_r(curl_getinfo($ch)); //break; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } //$patten = '/<span class="numbers"><strong>(.*?)<\/strong>/i'; //preg_match($patten, $text, $matches); //$left_sm = trim($matches[1]); //echo "free text left: $left_sm\n"; // // go to https://www.mymeteor.ie/go/freewebtext // $url = 'https://www.mymeteor.ie/go/freewebtext'; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); // methods to fetch a web page GET or POST curl_setopt($ch, CURLOPT_POST, false); // execute request //stores everything on the page as $text $text = curl_exec($ch); //echo $text; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } $patten = '/Free web texts left <input type="text" value="(\d*?)" disabled size=2>/i'; preg_match($patten, $text, $matches); $left_sm = trim($matches[1]); $body .= "free text left: $left_sm\n"; while ($left_sm > 0 and $num_sent < count($phone_list)) { // // add phone number // $phone = $phone_list[$num_sent]; $body .= 'No: ', $left_sm, ', sending to ', $phone; $patten = '/var CFID = (\d*?);/i'; preg_match($patten, $text, $matches); $cfid = $matches[1]; $patten = '/var CFTOKEN = (\d*?);/i'; preg_match($patten, $text, $matches); $cftoken = $matches[1]; // set URL $url = 'https://www.mymeteor.ie/mymeteorapi/index.cfm?event=smsAjax&CFID='.$cfid.'&CFTOKEN='.$cftoken.'&func=addEnteredMsisdns'; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); unset($post_data); $post_data['ajaxRequest'] = 'addEnteredMSISDNs'; $post_data['remove'] = '-'; $post_data['add'] = '0|'.$phone; curl_setopt($ch, CURLOPT_POST, true); // attach $post_data to Http headers on next line curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // execute request $text = curl_exec($ch); // $text is equal to source code of https://www.mymeteor.ie/go/freewebtext //echo $text; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } // // send message // // set URL $url = 'https://www.mymeteor.ie/mymeteorapi/index.cfm?event=smsAjax&func=sendSMS&CFID='.$cfid.'&CFTOKEN='.$cftoken; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); unset($post_data); $post_data['ajaxRequest'] = 'sendSMS'; $post_data['messageText'] = $message; curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_data); // execute request $text = curl_exec($ch); //echo $text; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } $body .= ' Done.'; $sql = "insert into phone_number_sent (phone, account, date_sent) values ('{$phone}', '{$account}', now())"; $obj->executesql($sql); $num_sent++; // // go to https://www.mymeteor.ie/go/freewebtext // $url = 'https://www.mymeteor.ie/go/freewebtext'; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, false); // execute request $text = curl_exec($ch); //echo $text; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } $patten = '/Free web texts left <input type="text" value="(\d*?)" disabled size=2>/i'; preg_match($patten, $text, $matches); $left_sm = trim($matches[1]); $body .= " Left: $left_sm\n"; } $body .= "\n"; // // log out // // set URL $url = 'https://www.mymeteor.ie/go/logout'; //echo "URL: $url\n"; // for debug curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, false); // execute request $text = curl_exec($ch); //echo $text; $error = curl_errno($ch); if($error>0) { $body .= 'Curl no: ' . curl_errno($ch), "\n"; $body .= 'Curl error: ' . curl_error($ch), "\n"; } } fclose($fp_s); } else { $body .= "No phone numbers found to be sent messages.\n"; } // close session curl_close($ch); $to = "[email protected]"; $subject = "Dublin Texting Finished At: ".date('Y-m-d H:i:s'); mail($to, $subject, $body); ?> Link to comment https://forums.phpfreaks.com/topic/190347-building-up-a-string-and-mail-funtion-problem/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.