JMail用于自定义组件编程

时间:2013-05-21 09:46:57

标签: joomla components jmail

我的代码在格式为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>

当我在json格式的控制器上使用相同的功能时,我收到“Mail Sent”消息。但Mail没有联系收件人;

1 个答案:

答案 0 :(得分:1)

我认为你的功能没有任何问题。

但是,我注意到,当电子邮件发送到收件箱时,Gmail非常挑剔:

  1. 所有全局配置&gt;服务器&gt; 邮件设置必须填写并生效。
  2. 这些设置必须用于JMail配置

  3. // 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();