Joomla 用于cutsom组件编程的JMail用法
我的代码在格式为html时工作Joomla 用于cutsom组件编程的JMail用法,joomla,components,jmail,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"));
<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>
公共功能部分命令()
{
$input=JFactory::getApplication()->input;
$mailer=JFactory::getMailer();
$config=JFactory::getConfig();
$mailer->setSender(数组(“email@email.com“,”姓名“);
$mailer->addRecipient(“somerecipient@somerecipent.com");
$body=“一些html消息”;
$mailer->isHTML(true);
$mailer->Encoding='base64';
$mailer->setBody($body);
$send=$mailer->send();
$respond=“”;
如果($send!==true){
$respond='发送电子邮件时出错:'。$send->message;
}否则{
$respond='Mail sent';
}
回音$应答;
}
当我在控制器上对json格式使用相同的函数时,我会收到“邮件已发送”消息。但邮件无法送达收件人 我认为你的功能没有问题 然而,我注意到Gmail在邮件进入收件箱时非常挑剔:
但我的代码适用于html格式,我尝试了其他电子邮件收件人。他们都工作。但是,每当我以相同的设置将此函数复制并粘贴到json格式的controllername.json.php文件时,电子邮件都不会到达收件人。我成功地收到了“邮件已发送”的消息。我想当格式是json时有些东西不起作用。我有个主意。因为您使用的是json控制器,所以我假设它是通过ajax执行的。可能您没有正确填充电子邮件字段(即,电子邮件发送到'somerecipient@somerecipent.com')? 尝试输出输入并与真实输入进行比较。
// 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();