dongxibeng5324 2012-08-22 16:09
浏览 38
已采纳

删除调试代码时,PHP邮件程序不会发送电子邮件

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

  • 写回答

2条回答 默认 最新

  • dqwr32867 2012-08-22 16:19
    关注

    The only likely answer that comes to mind is that, for whatever reason, $guestDetails is not defined anymore (e.g., it got renamed into $guestDetail somewhere else).

    This also would need the _log_r function 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 $guestDetails will probably not stop the process from completing. Actually ONLY the emails to the admin will get generated.

    Try something like

    if (!defined($guestDetails))
        ClassName::_log_r("mailer", "Not defined");
    if (empty($guestDetails))
        ClassName::_log_r("mailer", "empty");
    

    and see whether some more detail can be worried out.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 一道python难题
  • ¥15 用matlab 设计一个不动点迭代法求解非线性方程组的代码
  • ¥15 牛顿斯科特系数表表示
  • ¥15 arduino 步进电机
  • ¥20 程序进入HardFault_Handler
  • ¥15 oracle集群安装出bug
  • ¥15 关于#python#的问题:自动化测试
  • ¥20 问题请教!vue项目关于Nginx配置nonce安全策略的问题
  • ¥15 教务系统账号被盗号如何追溯设备
  • ¥20 delta降尺度方法,未来数据怎么降尺度