Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8418169
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T02:14:51+00:00 2026-06-10T02:14:51+00:00

I have a function that sends an email when a form is submitted. This

  • 0

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-10T02:14:52+00:00Added an answer on June 10, 2026 at 2:14 am

    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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a PHP application that sends email using the pear Mail function. Unfortunately
I have this Javascript function that sends username and password to php file through
Hey I have this code that sends an email with some data sent by
i have the following function in jQuery and javascript that creates a form element:
I have this code that takes info from a form and sends it to
Hi I have a php form that works perfectly when it sends an email
I have a jquery-ajax function that sends data to a php script and the
I have a javascript that calls a function each 1 minute. That function sends
I have an HTML form that takes inputted data and sends it via the
I have a contact form that is being submitted, I have PHP validation all

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.