Question

My code works when the format is html.

<pre>

public function partOrder()
{       
        $input=JFactory::getApplication()->input;
    $mailer =JFactory::getMailer();
    $config =JFactory::getConfig();
    $mailer->setSender(array("email@email.com","name"));
    $mailer->addRecipient("somerecipient@somerecipent.com");

    $body="Some html message";

    $mailer->isHTML(true);
        $mailer->Encoding = 'base64';
    $mailer->setBody($body);
    $send =$mailer->Send();
    $respond="";
    if ( $send !== true ) {
     $respond= 'Error sending email: ' . $send->message;
    } else {
        $respond= 'Mail sent';
    }

    echo $respond;

}

</pre>

When I use same function on controller for json format I get the "Mail Sent" message. But Mail doesn't reach to recipient;

No correct solution

OTHER TIPS

I don't think there's anything wrong with your function.

However, I noticed that Gmail is quite picky when it comes which emails come trough to inbox:

  1. All Global Configuration > Server > Mail Settings must be filled in and valid.
  2. These settings have to be used for JMail configuration

// Initialize some variables
$app            = JFactory::getApplication();
$mailer         = JFactory::getMailer();

// Get mailer configuration
$mailfrom       = $app->getCfg('mailfrom');
$fromname       = $app->getCfg('fromname');
$sitename       = $app->getCfg('sitename');

// Clean the email data
$contact_to     = JMailHelper::cleanAddress( $data['contact_to'] );
$subject        = JMailHelper::cleanSubject( $data['contact_subject'] );
$body           = JMailHelper::cleanBody(    $data['contact_message'] );
$reply_to_email = JMailHelper::cleanAddress( $data['contact_reply_to'] );
$reply_to_name  = JMailHelper::cleanLine(    $data['contact_reply_to_name'] );

// Construct mailer
$mailer
    ->addRecipient($contact_to)
    ->addReplyTo(array($reply_to_email, $reply_to_name))
    ->setSender(array($mailfrom, $fromname))
    ->setSubject($sitename . ': ' . $subject)
    ->setBody($body)
;

// Send email
$sent          = $mailer->Send();
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top