Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    problem with mail funtion and Building up a string using .=

    Hi everyone..

    I have a php script that works perfect

    PHP Code:
        $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

    PHP Code:
    #!/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($fpfilesize($message_file));
        
    fclose($fp);
        
        
    $fp_s fopen($source_file'r');
            
        
    $ch curl_init();

        
    curl_setopt($chCURLOPT_FOLLOWLOCATIONtrue);
        
    curl_setopt($chCURLOPT_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($chCURLOPT_COOKIEJAR'/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/cookie.txt');

        
    // get cookie
        
    curl_setopt($chCURLOPT_COOKIEFILE'/usr/local/pem/vhosts/100175/webspace/httpdocs/eurowebexperts.com/scripts/meteorDublin/cookie.txt');    

        
    // not to print out the results
        
    curl_setopt($chCURLOPT_RETURNTRANSFER1);
        
        
    curl_setopt($chCURLOPT_SSL_VERIFYPEERfalse);
        
        
    //
        // 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_s32)) !== 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($chCURLOPT_URL$url);
                
                unset(
    $post_data);
        
                
    $post_data['msisdn'] = $account;
                
    $post_data['pin']    = $password;
        
                
    curl_setopt($chCURLOPT_POSTtrue);
                
    curl_setopt($chCURLOPT_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($chCURLOPT_URL$url);
            
    // methods to fetch a web page GET or POST
                
    curl_setopt($chCURLOPT_POSTfalse);

                
    // 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 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($chCURLOPT_URL$url);
            
                    unset(
    $post_data);
        
                    
    $post_data['ajaxRequest'] = 'addEnteredMSISDNs';
                    
    $post_data['remove']      = '-';
                    
    $post_data['add']         = '0|'.$phone;
        
                    
    curl_setopt($chCURLOPT_POSTtrue);
                    
    // attach $post_data to Http headers on next line
                    
    curl_setopt($chCURLOPT_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($chCURLOPT_URL$url);
            
                    unset(
    $post_data);
        
                    
    $post_data['ajaxRequest'] = 'sendSMS';
                    
    $post_data['messageText'] = $message;
        
                    
    curl_setopt($chCURLOPT_POSTtrue);
                    
    curl_setopt($chCURLOPT_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($chCURLOPT_URL$url);
            
                    
    curl_setopt($chCURLOPT_POSTfalse);

                    
    // 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($chCURLOPT_URL$url);
            
                
    curl_setopt($chCURLOPT_POSTfalse);

                
    // 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);
            
    ?>
    Last edited by kevinkhan; 01-30-2010 at 05:10 PM.

  • #2
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    Looks like you used a comma on the line below instead of a period.

    PHP Code:
    $body .=  'Message lenght (should be less than 160) is: 'strlen($message), "\n"
    Dave .... HostMonster for all of your hosting needs

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by djm0219 View Post
    Looks like you used a comma on the line below instead of a period.

    PHP Code:
    $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?

  • #4
    Senior Coder djm0219's Avatar
    Join Date
    Aug 2003
    Location
    Wake Forest, North Carolina
    Posts
    1,312
    Thanks
    4
    Thanked 206 Times in 203 Posts
    Look closely at that line. You've used a comma (,) instead of a period (.) for string concatenation. That line should read:

    PHP Code:
    $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.
    Dave .... HostMonster for all of your hosting needs

  • Users who have thanked djm0219 for this post:

    kevinkhan (01-30-2010)

  • #5
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    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.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • Users who have thanked _Aerospace_Eng_ for this post:

    kevinkhan (01-30-2010)

  • #6
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    ok thanks guys..

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

    Thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •