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
The only likely answer that comes to mind is that, for whatever reason,
$guestDetailsis not defined anymore (e.g., it got renamed into$guestDetailsomewhere else).This also would need the
_log_rfunction to redefine the argument if it does not exist.If you check the mails being sent to the CC: only, they will arrive – an invalid
$guestDetailswill probably not stop the process from completing. Actually ONLY the emails to the admin will get generated.Try something like
and see whether some more detail can be worried out.