0

我的代码在格式为 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 格式使用相同的功能时,我收到“已发送邮件”消息。但是邮件没有到达收件人;

4

1 回答 1

1

我不认为你的功能有什么问题。

但是,我注意到 Gmail 在处理哪些电子邮件进入收件箱时非常挑剔:

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

// 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();
于 2013-05-21T12:13:17.977 回答