Welcome Guest, Not a member yet? Register   Sign In
Sending eMails with CronJob
#1

(This post was last modified: 01-11-2019, 12:44 AM by ciadmin. Edit Reason: potential SEO spam )

Hi,
I have a script that is run via a cronjob, everything works fine except for: 
$this->email->to($user->mail);

The eMail to [email protected] works fine

                $this->load->library('email');
                $config_mail['mailtype'] = 'html';
                $this->email->initialize($config_mail);
                $this->email->from($settings['noreply'], 'True Blue Locals');
                $this->email->to($user->mail);

                $this->email->to("[email protected]");

Just wondering if there is something wrong with the formatting.

Any guidance will be appreciated

Cheers
Ron
Cheers
Ron
Reply
#2

@VK4JE,

Where do you get $user->mail value from? What is it's value when the crontab runs? Is it possible to see the whole script?
Reply
#3

(This post was last modified: 01-12-2019, 07:16 PM by VK4JE. Edit Reason: more detail )

(01-11-2019, 06:18 AM)php_rocs Wrote: @VK4JE,

Where do you get $user->mail value from?  What is it's value when the crontab runs?  Is it possible to see the whole script?

Yes it is, I tried to post it here, but the post was denied.

I will try to add it as a zip file.

The full story is:
In an effort to send a remember email stating that the Membership Package will expire in 7, 5, 3, 1 days
The current issues with coding Start at Line 1267 and End Line 1632
 
I have added new columns to the Database for users
"data_expire_7_sent"
"data_expire_5_sent"
"data_expire_3_sent"
"data_expire_1_sent"
data_expire_package_sent

I have added new eMails for each

I have followed the Developers lead with the coding for data_expire_package_sent

The correct eMails are sent, the date is filled into the correct database field, however

My additional 7, 5, 3, 1 days emails continue to be sent every time the cronjob runs until data_expire_package_sent  cronjob runs and completes, then they all stop.

The objective is to send only one eMail to the $user and admin as each expiry date is reached.
The issue are:
Multiple 7, 5, 3, 1 emails (new one send every cronjob run) until data_expire_package_sent runs
No emails are ever sent to $user
 


Cheers
Ron

Attached Files
.zip   cronjob.php (1).zip (Size: 8.67 KB / Downloads: 54)
Cheers
Ron
Reply
#4

@VK4JE,

Questions...

1. What value is $user->data_expire_package_sent suppose to be if it is not NULL?
2. Also, I would use === instead of ==.
3. I'm also wondering why you have exit() in the code? This actually terminates the code. I only use exit() when I'm trouble shooting. If this is not for testing purposes then you need to remove all instances of exit() out of this script. THIS MAY BE YOUR ISSUE.
Reply
#5

@VK4JE,

SUGGESIONS:
1. Instead of creating multiple functions to handle 7,5,3,1 days until expiration why not just a single function that does it all. The function would be able to determine numbers of days until expiration and if the number of days left is either 7,5,3,1 then send an email.
2. Instead of loading your models multiple times in the functions why not declare the most common models once in the __construct function. This will keep you from repeating the same code.
Reply
#6

(This post was last modified: 01-14-2019, 04:47 PM by VK4JE. Edit Reason: more info )

(01-14-2019, 08:04 AM)php_rocs Wrote: @VK4JE,

SUGGESIONS:
1.  Instead of creating multiple functions to handle 7,5,3,1 days until expiration why not just a single function that does it all.  The function would be able to determine numbers of days until expiration and if the number of days left is either 7,5,3,1 then send an email.
2. Instead of loading your models multiple times in the functions why not declare the most common models once in the __construct function.  This will keep you from repeating the same code.
Hi php_rocs,
Thank you for your reply and suggestions,
The scripts that I am working with were 'built' by a developer that I purchased them from. 
The script that I zipped up for you is the Developers Solution. 
So I am trying to work with what I have, good or bad.

To be honest you solution and approach sounds clean and simple, I just do not know how to do it.

My main issue is that the users are not being emailed as their membership moves towards expiry.

Regards
Ron
Cheers
Ron
Reply
#7

(This post was last modified: 01-14-2019, 08:03 PM by php_rocs.)

@VK4JE,

Ok, wow. I'll take another look at the code. I do however have more questions.
Do you have a test environment where you can test/debug the code?
If you are seeing errors, what is the error message(s) that you are seeing?
Do you still have contact with the developer? If so, maybe you could mention the issue that you are having with it to him as well.
Reply
#8

Hi php_rocs,
Currently there is no upto date Testing url as I have had two developers working on the site and both wanted to work live. This is not to say I can not create a testing url.

I am NOT getting error messages, the site on the face of it is working fine.

My two main problems have been:
Having only One 7, 5, 3, 1 Expiry Reminder eMail go out, instead of repeat emails every time the Cronjob runs. This issue maybe be resolved as I received instructions from the Script Developer which I am testing now.

The Second issue and probably the most important is that although the script appears to coded correctly the Expiry Reminders to the clients is not being sent.

All other eMails are being sent from other sections of the website without an issue, but for some reason the eMail addresses that are in the database table 'user' column 'mail' refuse to go.

Yes, I am on good terms with the Developer, and I have been 'banging' on about these issues for a while.

Cheers
Ron
Cheers
Ron
Reply
#9

(01-14-2019, 11:32 PM)VK4JE Wrote: Hi php_rocs,
Currently there is no upto date Testing url as I have had two developers working on the site and both wanted to work live. This is not to say I can not create a testing url.

I am NOT getting error messages, the site on the face of it is working fine.

My two main problems have been:
Having only One 7, 5, 3, 1 Expiry Reminder eMail go out, instead of repeat emails every time the Cronjob runs. This issue maybe be resolved as I received instructions from the Script Developer which I am testing now.

The Second issue and probably the most important is that although the script appears to coded correctly the Expiry Reminders to the clients is not being sent.

All other eMails are being sent from other sections of the website without an issue, but for some reason the eMail addresses that are in the database table 'user' column 'mail' refuse to go.

Yes, I am on good terms with the Developer, and I have been 'banging' on about these issues for a while.

Cheers
Ron

[RESOLVED]

The Developer de bugged the code resolving the multi duplicate eMails
and I resolved the eMail being sent to the client by using this coding;
$this->email->to($user->mail);
$this->email->cc([email protected]); 

Thanks for the Help and Ideas

Cheers
Ron
Cheers
Ron
Reply
#10

@VK4JE,

I'm glad to know that you and the developer were able to resolve it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB