Jump to content

PHPmailer... why doesn't this work inside a function?


Jack.Straw

Recommended Posts

Hi, i'm totally confused here.  I'm learning to use PHPmailer.  It works just fine for me unless i put it inside its own function.  Can anyone tell me why?

This code works fine:
[code]
if ($TimeDif>7776000) {
  require_once($_SERVER['DOCUMENT_ROOT'].'/emersonstore/config.php');
  require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
  $mailer = new FreakMailer();
  $mailer->Subject = 'Online Emerson Store Report from Metro Lighting';
  $mailer->Body = "The following summary was generated and mailed automatically. ";
  $mailer->AddAddress('[email protected]', 'Jack Straw');
  $mailer->Send();
  $mailer->ClearAddresses();
  $mailer->ClearAttachments();
  mysql_query("UPDATE report SET Date='$Today' WHERE Purpose='LastUpdate'");
}
[/code]


This code does not:
[code]
function SendReport() {
  require_once($_SERVER['DOCUMENT_ROOT'].'/emersonstore/config.php');
  require_once($_SERVER['DOCUMENT_ROOT'].'/lib/MailClass.inc');
  $mailer = new FreakMailer();
  $mailer->Subject = 'Online Emerson Store Report from Metro Lighting';
  $mailer->Body = "The following summary was generated and mailed automatically. ";
  $mailer->AddAddress('[email protected]', 'Jack Straw');
  $mailer->Send();
  $mailer->ClearAddresses();
  $mailer->ClearAttachments();
  mysql_query("UPDATE report SET Date='$Today' WHERE Purpose='LastUpdate'");
}

if ($TimeDif>7776000) {
  SendReport();
}
[/code]

I know the function gets run because the mysql query is executed, but it doesn't send out the email

Can anyone help me understand why?

Thanks in advance,
-Jack

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.