joomla - JMail usage for cutsom component programming -
my code works when format 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 use same function on controller json format "mail sent" message. mail doesn't reach recipient;
i don't think there's wrong function.
however, noticed gmail quite picky when comes emails come trough inbox:
- all global configuration > server > mail settings must filled in , valid.
- these settings have used jmail configuration
// initialize variables $app = jfactory::getapplication(); $mailer = jfactory::getmailer(); // mailer configuration $mailfrom = $app->getcfg('mailfrom'); $fromname = $app->getcfg('fromname'); $sitename = $app->getcfg('sitename'); // clean 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();
Comments
Post a Comment