...

View Full Version : problem with mail funtion and Building up a string using .=



kevinkhan
01-30-2010, 12:12 PM
Hi everyone..

I have a php script that works perfect


$to = "info@eurowebexperts.com";
$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 = "info@eurowebexperts.com";
$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 = "info@eurowebexperts.com";
$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 = "info@eurowebexperts.com";
$subject = "Dublin Texting Finished At: ".date('Y-m-d H:i:s');

mail($to, $subject, $body);

?>

djm0219
01-30-2010, 02:11 PM
Looks like you used a comma on the line below instead of a period.


$body .= 'Message lenght (should be less than 160) is: ', strlen($message), "\n";

kevinkhan
01-30-2010, 04:01 PM
Looks like you used a comma on the line below instead of a period.


$body .= 'Message lenght (should be less than 160) is: ', strlen($message), "\n";

What do you mean?

Is the above code not in the correct format?

djm0219
01-30-2010, 04:11 PM
Look closely at that line. You've used a comma (,) instead of a period (.) for string concatenation. That line should read:


$body .= 'Message lenght (should be less than 160) is: ' . strlen($message) . "\n";

There may be other problems too but that one jumped out at me.

_Aerospace_Eng_
01-30-2010, 05:00 PM
Concatenation should be done with a . (period/full stop). I think only echo allows you to use commas to put multiple strings together. You should be getting a syntax error on your $body when you use the commas. I suggest you turn on full error reporting.

kevinkhan
01-30-2010, 05:24 PM
ok thanks guys..

you were right.. I changed all , to . and it worked perfect

Thanks



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum