Jack.Straw Posted December 1, 2006 Share Posted December 1, 2006 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 Link to comment https://forums.phpfreaks.com/topic/29161-phpmailer-why-doesnt-this-work-inside-a-function/ Share on other sites More sharing options...
Jack.Straw Posted December 2, 2006 Author Share Posted December 2, 2006 I figured it out.I had to register the array $mailer as a global :) Link to comment https://forums.phpfreaks.com/topic/29161-phpmailer-why-doesnt-this-work-inside-a-function/#findComment-133746 Share on other sites More sharing options...
Jack.Straw Posted December 2, 2006 Author Share Posted December 2, 2006 ahhh ya, that was it. Thanks!!!! Link to comment https://forums.phpfreaks.com/topic/29161-phpmailer-why-doesnt-this-work-inside-a-function/#findComment-133876 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.