I have a function that sends an email when a form is submitted. This function contains the following if-statement:
if ($guestDetails)
{
$mailer->addRecipient($guestDetails->email);
$mailer->addCC( $config->get('emails_admin_email'));
$mailer->setSubject( $subject );
$mailer->setBody($template_layout);
$mailer->IsHTML($mode);
$mailer->setSender(array( $mailfrom, $fromname ));
$sent = $mailer->send();
}
Recently, this function has stopped working (i.e. the emails are no longer being sent). To investigate what is going on I have modified the code to log some of the variables as there was nothing being recorded in the PHP Error log. Here is how the if-statement looks now:
$testArr = array();
ClassName::_log_r("guestdetails", $guestDetails);
if ($guestDetails)
{
ClassName::_log_r("got into if", $testArr);
$mailer->addRecipient($guestDetails->email);
$mailer->addCC( $config->get('emails_admin_email'));
$mailer->setSubject( $subject );
$mailer->setBody($template_layout);
$mailer->IsHTML($mode);
$mailer->setSender(array( $mailfrom, $fromname ));
$sent = $mailer->send();
ClassName::_log_r("mailer", $mailer);
ClassName::_log_r("sent", $sent);
} else
ClassName::_log_r("got into else", $testArr);
The _log_r is just a function that writes to a text file the contents of the given variable. Once I added this "debug" code, the emails started being sent once again and the log correctly records "got into if". Removing the afore mentioned debug code stops the emails from being sent once again.
I am puzzled at what could be possibly going on here. Has anyone ever came across anything like this? Why are emails not being sent when the debug code is removed? Please let me know if more information is needed. Thanks!
PS the code is written in PHP and the server is running PHP 5.3.10