I have a basic template that I plan on running on a cron job. I have stripped out the unnecessary parts, but the template still sends duplicate emails.

Here is the code:



    $this->EE->email->wordwrap = true;
    $this->EE->email->mailtype = 'text';


What am I doing wrong? It sends me two emails.

  • 2
    Just to be clear, does the cron just trigger a regular EE template? I have seen this issue before when trying send email fron your site's homepage. The template will trigger the email twice. Outside of that I don't know what else would cause it. Dec 21 '12 at 18:54

When I've had this happen before with regular php mail code, I've used something like this:

$sent ="";
if ($sent == '0') {
  $sent = 1;
  • 1
    Talk about a hack for a workaround. I could see where the logic solves this issue, but I really want to know why you would have to use that logic to solve such problem. Dec 21 '12 at 20:48
  • Yes, the cron job accesses the template as you normally would view a page. I have other code that echoes to the page directly after the mail function is called. The weird thing is that the page only echoes one line, but sends two emails
    – hfrancke
    Dec 21 '12 at 21:17
  • Ha! Well, it will work! Is the code inside a loop of some sort? Can you post the whole template code to www.pastie.org?
    – Anna_MediaGirl
    Dec 21 '12 at 21:56
  • Any URL rewriting going on in .htaccess that might be getting in the way? Can you print out the time in the email. Is it exactly the same in both emails?
    – Anna_MediaGirl
    Dec 21 '12 at 22:10
  • The times are the same.
    – hfrancke
    Jan 2 '13 at 15:41

I have come to a solution. There was never anything wrong with the code. I have PageSpeed installed as an extension on Chrome. Somehow this extension was causing the site to load twice or three times, which sent several emails.

  • Good job of tracking this down! Make sure to mark your answer as the "correct" one by clicking on the checkbox to the left of the answer.
    – Anna_MediaGirl
    Jan 7 '13 at 19:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.