Welcome Guest, Not a member yet? Register   Sign In
Email Helper only sends one of three emails successfully
#5

[eluser]Myles Wakeham[/eluser]
[quote author="BrandonDurham" date="1253583726"]
How would you change the code above? It's strange... when testing locally (MAMP) it works perfectly, but when I upload it to the server (adlucent.com) it only send the email to my personal address.[/quote]

Does sound like a server configuration setting issue. Some ISPs will throttle outgoing emails to protect themselves from spam. Sometimes this is done by throttling the number of outgoing emails allowed in a time period (ie. no more than 1 per 20 seconds, or something like that). Other times there is a max put per hour of total emails allowed out (ie. 300 max per hour). Depends on your hosting provider.

As for the code, what I would normally do is in the controller, I would do the load of the library. The controller then becomes the 'parent' and you would reference in your function the controller like this:

Code:
function DoSomething(){
        $contr = & get_instance();
    $email_object = $contr->email;

        $email_object->clear();
        $email_object->subject = 'This is the subject';
etc.

It doesn't really matter what the class is that you are referencing (CI classes, your own classes, etc.). If they are instantiated in the controller, you refer to the through the & get_instance() call to get a handle to where they were created. What you are doing is to load them repetitively in the function, so that each time the function is called it has to check if it needs to create a new object each time, which probably doesn't need to be done. I may be being pedantic here, but its just a coding habit that I like (I like to know where my objects are being created from).

As a previous poster said, to be absolutely sure that each new reference from load is clear, you should do some form of clear() call. This is the same regardless of where the object is being instantiated from of course. I don't know the PHP code of the email helper (I use phpMailer for my email sending) but if I remember the code for library initialization, it checks to see if the library was already loaded. If not, it loads it. If it was previously loaded, however, it just returns a handle to that object. So its entirely likely that your previous email settings are being left over each time. The clear() call is critical in that case, I would assume.

Myles


Messages In This Thread
Email Helper only sends one of three emails successfully - by El Forum - 09-21-2009, 05:45 PM



Theme © iAndrew 2016 - Forum software by © MyBB