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 8 of 8
  1. #1
    New to the CF scene
    Join Date
    Jun 2013
    Location
    Nevada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Hello, I am new to PHP and need your help with .

    My website have the expiry email notification but is not working and need some help.
    can anyone review this code and tell me if is correct or what needs to be done to make it work.
    Highly appreciated,

    code start:


    <?php

    require_once("initvar file here");

    require_once("config file here");
    $fp = fopen($ui, "r");
    stream_set_timeout($fp, 10);
    $li = fread($fp, 19);
    fclose($fp);

    if ($li == $domain) {


    $expiry_date = (time()+$expire_ads_ahead);
    $upcoming_date = date("l, j F, Y H:i", $expiry_date);

    $res_sql = "SELECT * FROM ".$t_ads."
    WHERE UNIX_TIMESTAMP(expireson) <= '".$expiry_date."'
    AND reminder = '0'";

    $resc = mysql_query($res_sql);

    } else {
    echo $ilk ;
    die();
    }
    while ( $row = mysql_fetch_assoc($resc) )
    {
    $codemd5 = $row["code"];
    $codemd5 = md5($codemd5);

    $subj = $lang['RENEW_EMAIL_SUBJ'] . ' (' . $row["adtitle"] . ')';
    $msg = "Hello, this is a friendly reminder that your ad is about to expire on (".$upcoming_date.") at ".$site_name.".

    Please click on the following link to visit your ad's edit page if you wish to renew it:

    ".$script_url."/?view=edit&isevent=&adid=".$row["adid"]."&codemd5=".$codemd5."&cityid=".$row["cityid"]."

    On the edit page click on the \"Renew Ad\" located at the top to renew your listing. You may also click on the \"Promote your ad\" to upgrade your current basic listing to a featured listing.

    Thank you,
    Webmaster, ".$site_name."
    ";


    $to = $row["email"];
    //$to='none@yadda.com'; // testing
    $from = $site_email;


    mail($to, $subj, $msg, "From: $from\r\n");

    echo $row["adid"].' '.$row["createdon"].' '.$row["expireson"].' - email sent to '.$row["email"].'<br>'; // output

    mysql_query("UPDATE ".$t_ads." SET reminder='1' WHERE adid='".$row["adid"]."'");
    $i++;
    }

    if ( $reminder_email_master == 1 )
    {
    if ( $i <= 0 )
    {
    $i = "No";
    }
    $master_subject = "Reminder Cron Job Ran";
    $master_msg = "$i reminder emails have been sent.

    This is an automated message sent from $site_name";
    mail($site_email, $master_subject, $master_msg, "From: $site_email\r\n");
    }

    ?>

    code end:

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,089
    Thanks
    51
    Thanked 506 Times in 493 Posts
    Quote Originally Posted by Stangcode View Post
    My website have the expiry email notification but is not working and need some help.
    can anyone review this code and tell me if is correct or what needs to be done to make it work.
    More to the point, have you tried to run the code?
    Does it do what you expect?
    Do you get any errors?

    If you can answer those then perhaps we can help you better. Also please put your code in the php tags
    My helpful sig is on vacation trying to loose some weight. It got a bit fat and caused a few problems but it will be back at some point!

  • #3
    New to the CF scene
    Join Date
    Jun 2013
    Location
    Nevada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i have tried running the code through the browser and didnt get any errors, also tried running the code in cron jobs and no errors.
    i also did a test by adding an expired Ad and changed the "$to = $row["email"];" to my email and i am not receiving any notifications.



    PHP Code:

    <?php

    require_once("initvar file here");

    require_once(
    "config file here");
    $fp fopen($ui"r");
    stream_set_timeout($fp10);
    $li fread($fp19);
    fclose($fp);

    if (
    $li == $domain) {


    $expiry_date = (time()+$expire_ads_ahead);
    $upcoming_date date("l, j F, Y H:i"$expiry_date); 

    $res_sql "SELECT * FROM ".$t_ads.
    WHERE UNIX_TIMESTAMP(expireson) <= '"
    .$expiry_date."' 
    AND reminder = '0'"
    ;

    $resc mysql_query($res_sql);

    } else {
    echo 
    $ilk ;
    die();
    }
    while ( 
    $row mysql_fetch_assoc($resc) )
    {
    $codemd5 $row["code"];
    $codemd5 md5($codemd5);

    $subj $lang['RENEW_EMAIL_SUBJ'] . ' (' $row["adtitle"] . ')';
    $msg "Hello, this is a friendly reminder that your ad is about to expire on (".$upcoming_date.") at ".$site_name.". 

    Please click on the following link to visit your ad's edit page if you wish to renew it: 

    "
    .$script_url."/?view=edit&isevent=&adid=".$row["adid"]."&codemd5=".$codemd5."&cityid=".$row["cityid"]."

    On the edit page click on the \"Renew Ad\" located at the top to renew your listing. You may also click on the \"Promote your ad\" to upgrade your current basic listing to a featured listing. 

    Thank you,
    Webmaster, "
    .$site_name."
    "
    ;


    $to $row["email"];
    //$to='none@yadda.com'; // testing
    $from $site_email;


    mail($to$subj$msg"From: $from\r\n");

    echo 
    $row["adid"].' '.$row["createdon"].' '.$row["expireson"].' - email sent to '.$row["email"].'<br>'// output

    mysql_query("UPDATE ".$t_ads." SET reminder='1' WHERE adid='".$row["adid"]."'");
    $i++;
    }

    if ( 
    $reminder_email_master == )
    {
    if ( 
    $i <= )
    {
    $i "No";
    }    
    $master_subject "Reminder Cron Job Ran";
    $master_msg "$i reminder emails have been sent.

    This is an automated message sent from $site_name"
    ;
    mail($site_email$master_subject$master_msg"From: $site_email\r\n");
    }

    ?>

  • #4
    New to the CF scene
    Join Date
    Jun 2013
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Hello,

    If I was you I would add some text/echo statement's next to the PHP statement that send's the email, to make sure your if statement's are working as you would expect and the script is getting to the correct stage.

    ,Ashley

  • #5
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    PHP Code:
    ini_set('display_errors'1);
    error_reporting(E_ALL); 
    Add to top.
    There are too many variables here that we cannot confirm exist.

    Also, you should put your code in [php][/php] tags since it preserves the formatting.
    PHP Code:
    <?php

    require_once("initvar file here");

    require_once(
    "config file here");
    $fp fopen($ui"r");
    stream_set_timeout($fp10);
    $li fread($fp19);
    fclose($fp);

    if (
    $li == $domain) {


    $expiry_date = (time()+$expire_ads_ahead);
    $upcoming_date date("l, j F, Y H:i"$expiry_date); 

    $res_sql "SELECT * FROM ".$t_ads.
                WHERE UNIX_TIMESTAMP(expireson) <= '"
    .$expiry_date."' 
                AND reminder = '0'"
    ;
                
    $resc mysql_query($res_sql);

    } else {
    echo 
    $ilk ;
    die();
    }
    while ( 
    $row mysql_fetch_assoc($resc) )
    {
    $codemd5 $row["code"];
    $codemd5 md5($codemd5);

    $subj $lang['RENEW_EMAIL_SUBJ'] . ' (' $row["adtitle"] . ')';
    $msg "Hello, this is a friendly reminder that your ad is about to expire on (".$upcoming_date.") at ".$site_name.". 

    Please click on the following link to visit your ad's edit page if you wish to renew it: 

    "
    .$script_url."/?view=edit&isevent=&adid=".$row["adid"]."&codemd5=".$codemd5."&cityid=".$row["cityid"]."

    On the edit page click on the \"Renew Ad\" located at the top to renew your listing.  You may also click on the \"Promote your ad\" to upgrade your current basic listing to a featured listing.  

    Thank you,
    Webmaster, "
    .$site_name."
    "
    ;


    $to $row["email"];
    //$to='none@yadda.com'; // testing
    $from $site_email;


    mail($to$subj$msg"From: $from\r\n");

    echo 
    $row["adid"].'  '.$row["createdon"].' '.$row["expireson"].' - email sent to '.$row["email"].'<br>'// output

    mysql_query("UPDATE ".$t_ads." SET reminder='1' WHERE adid='".$row["adid"]."'");
    $i++;
    }

        if ( 
    $reminder_email_master == )
        {
            if ( 
    $i <= )
            {
                
    $i "No";
            }    
            
    $master_subject "Reminder Cron Job Ran";
            
    $master_msg "$i reminder emails have been sent.
            
            This is an automated message sent from $site_name"
    ;
            
    mail($site_email$master_subject$master_msg"From: $site_email\r\n");
        }

    ?>
    There is a lot of potential here for undefined variables. The entire iteration itself could produce nothing since its outside of the if branch which the query is executed. Granted, there is a die, but still that's pretty bad practice overall.
    Start by adding the error reporting. Also, make sure you view your HTML source and *don't* see the PHP code within it. If you do, you simply don't have a PHP processor running.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #6
    New to the CF scene
    Join Date
    Jun 2013
    Location
    Nevada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question

    Quote Originally Posted by Fou-Lu View Post
    There is a lot of potential here for undefined variables. The entire iteration itself could produce nothing since its outside of the if branch which the query is executed. Granted, there is a die, but still that's pretty bad practice overall.
    Start by adding the error reporting. Also, make sure you view your HTML source and *don't* see the PHP code within it. If you do, you simply don't have a PHP processor running.

    Thanks for all the response,
    but since all other php files work fine in cron jobs i would think that the php processor in running and seems like this code is the only problem child.
    with you experience, do you have a code that works and could replace mine to make things more simple?

  • #7
    God Emperor Fou-Lu's Avatar
    Join Date
    Sep 2002
    Location
    Saskatoon, Saskatchewan
    Posts
    16,978
    Thanks
    4
    Thanked 2,659 Times in 2,628 Posts
    That's not a correct assumption. Cron jobs execute directly the php executable whilst the web-browser will invoke either a module apache hook or fcgi build on the webserver. They are two completely distinct ways of connecting to the php processor, and since one goes through the webserver, you may need to perform extra configurations. Of course though, if a single script is parsed on a webserver, then all others will be as well (at least for that directory a .htaccess can technically override). So a simple <?php phpinfo(); to a script will tell you if its working when you access that.
    Oh, and you will need to make sure you're using the http:// protocol and not the file:// protocol.

    Figuring out where you are really is a simple matter of using echo's. I personally use xdebug with the eclipse IDE, so walking through it is much easier, but simple prints will work as well. Quick inspection looks to have no parser errors, so echo's should be displayed as it processes along.
    PHP Code:
    header('HTTP/1.1 420 Enhance Your Calm'); 

  • #8
    New to the CF scene
    Join Date
    Jun 2013
    Location
    Nevada
    Posts
    5
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Ok, so a ran the display error code and got this back.

    Notice: Undefined index: user_id in /public_html/accounts/includes/validation.php on line 58

    Notice: Undefined index: username in /public_html/accounts/includes/validation.php on line 59

    Notice: Undefined index: email in /public_html/accounts/includes/validation.php on line 60

    Notice: Undefined index: search_user_ip in /public_html/accounts/includes/validation.php on line 61

    Notice: Undefined index: row_username in /public_html/accounts/includes/validation.php on line 62

    Notice: Undefined index: img_upload in /public_html/accounts/includes/validation.php on line 67
    


    This is the validation file i found.
    Like i said, i am new to this so would need your help on what needs to be done to make it work.
    Thanks,

    PHP Code:
    <?php

    if( !defined('IN_SCRIPT') )
    {
        die(
    'Unauthorized Access is Forbidden');
    }



    // empty vars

    $error 0;
    $name_too_short '';
    $error_message '';


    if ( !empty(
    $_POST) )
    {

        
    // posted invals
        
    $int_vars = array('savecookies''level''active');
        
        foreach(
    $int_vars as $ints
        { 
            $
    $ints intval($_POST[$ints]); 
        } 
        
        
    // posted clean vars
        // User Edit Profile

        
    $update_username clean_var($_POST['update_username']);
        
    $update_password clean_var($_POST['update_password']);
        
    $update_email clean_var($_POST['update_email']);

        

        
    $cle_vars = array('user''pass''submit''how_found''forgot_login''password''password_confirm''upload_type',
        
    'delete_user');
        
        foreach(
    $cle_vars as $clevs
        { 
            $
    $clevs clean_var($_POST[$clevs]); 
        } 
        
    }

    if ( !empty(
    $_GET) )
    {
        
    $action clean_var($_GET['action']);
        
    $confirm clean_var($_GET['confirm']);
        
    $conf_join clean_var($_GET['conf_join']);
        
    $profile_value clean_var($_GET['profile_value']);

    }

    // Request vars

    $user_id intval($_REQUEST['user_id']);
    $username clean_var($_REQUEST['username']);
    $email clean_var($_REQUEST['email']);
    $search_user_ip $_REQUEST['search_user_ip'];
    $row_username clean_var($_REQUEST['row_username']);


    // NOTE: img_upload file type doesn't need security

    $img_upload_type $_FILES["img_upload"]["type"];



    ?>


  •  

    Posting Permissions

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