custom email code not sending returns false

$link = '<a href="http://'.$root_url.'/index.php?module=CB_SupportTickets&action=DetailView&record='.$bean->id.'"/> Click Here</a>';

$emailObj = new Email();
$defaults = $emailObj->getSystemDefaultEmail();
$mail = new SugarPHPMailer();
$mail->setMailerForSystem();
$mail->From = $defaults['email'];
$mail->FromName = $defaults['name'];
$mail->Subject = "Support Ticket";
$mail->Body = "test ".$ticketNumber." is now ".$bean->resolution. ". ".$link;
$mail->prepForOutbound();
$mail->AddAddress("myawesome@email.com");
$mail->Send();

This is the result of the print_r the upper results only:

  • oe (Object) OutboundEmail
  • protocol (String, 6 characters ) tcp://
  • preppedForOutbound (Boolean) FALSE
  • disclosureEnabled (NULL)
  • disclosureText (NULL)
  • isHostEmpty (Boolean) FALSE
  • opensslOpened (Boolean) TRUE
  • Version (String, 6 characters ) 5.2.13
  • Priority (NULL)
  • CharSet (String, 5 characters ) UTF-8
  • ContentType (String, 10 characters ) text/plain
  • Encoding (String, 16 characters ) quoted-printable
  • ErrorInfo (String, 0 characters )
  • Hi ,

    You can try below code 

    require_once('modules/Emails/Email.php');
            global $current_user, $mod_strings, $sugar_config, $locale, $timedate;
       
            $admin = new Administration();
            $admin->retrieveSettings();
            if(empty($admin->settings['notify_send_from_assigning_user'])) {
                $From = $admin->settings['notify_fromaddress'];
                $FromName = (empty($admin->settings['notify_fromname'])) ? "" : $admin->settings['notify_fromname'];
            } else {
                // Send notifications from the current user's e-mail (if set)
                $fromAddress = $current_user->emailAddress->getReplyToAddress($current_user);
                $fromAddress = !empty($fromAddress) ? $fromAddress : $admin->settings['notify_fromaddress'];
                $From = $fromAddress;
                //Use the users full name is available otherwise default to system name
                $from_name = !empty($admin->settings['notify_fromname']) ? $admin->settings['notify_fromname'] : "";
                $from_name = !empty($current_user->full_name) ? $current_user->full_name : $from_name;
                $FromName = $from_name;
            }
           
           
            ## START Send Email
            $mail = new SugarPHPMailer();
           
            //$mail->prepForOutbound();
            //$mail->setMailerForSystem();
            $mail->setMailer();
           
            $mail->From = $From;
            $mail->FromName = $FromName;
           
            $mail->Sender = $mail->From;
            $mail->Subject = "Support Ticket";
            $mail->Body = "test ".$ticketNumber." is now ".$bean->resolution. ". ".$link;
            $mail->IsHTML(true);
           
            $mail->AddReplyTo($mail->From,$locale->translateCharsetMIME(trim( $mail->FromName), 'UTF-8', $OBCharset));
           
            $mail->AddAddress('myawesome@email.com', "Email Name(Optional)");

    Hope this helpful!!!

    Dipesh

    Offshore Evolution Pvt Ltd

  • will you explain the difference between the two? Thank you

  • Hi,

    My code in From name & From Email Address Set.

    if(!$mail->Send()){
          return false;
          //echo "Mail did not send";
    }

    return true;