您的位置:首页 > Web前端 > HTML

Joomla如何发送一封 简单的&&复杂的 邮件

2017-08-02 10:48 525 查看
简单的

//获取对象与获取系统参数
$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
//设置发件人
$sender = array(
 $config->get('mailfrom'),
 $config->get('fromname')
);
$mailer->setSender($sender);
//设置收件人
$recipient = array('person1@domain.com');
$mailer->addRecipient($recipient);
//设置内容
$mailer->setSubject('subject');
$mailer->setBody('body');
//发送邮件
$send = $mailer->Send();
if ($send !== true){
 echo 'Error sending email: ' . $send->__toString();
} else {
 echo 'Mail sent';
}

复杂的

//实例化与获取系统参数$mailer = JFactory::getMailer();
$config = JFactory::getConfig();
//设置发件人
$sender = array(
 $config->get('mailfrom'),
 $config->get('fromname')
);
$mailer->setSender($sender);
//设置收件人
$recipient = array('person1@domain.com');
$mailer->addRecipient($recipient);
//设置内容
$body = 'aaa<img src="cid:logo_id" alt="logo"/></div>bbb';
$mailer->isHTML(true);
$mailer->Encoding = 'base64';
$mailer->setSubject('subject');
$mailer->setBody($body);
$mailer->AddEmbeddedImage(JPATH_COMPONENT.'/assets/logo128.jpg', 'logo_id', 'logo.jpg', 'base64', 'image/jpeg');
$mailer->addAttachment(JPATH_COMPONENT.'/assets/document.pdf');
//发送邮件
$send = $mailer->Send();
if ($send !== true) {
 echo 'Error sending email: ' . $send->__toString();
} else {
 echo 'Mail sent';
}

方法 isHTML(true) 是指开启html邮件模式。

属性 Encoding 用于发送HTML邮件你设置编码为base64,避免多余的字符输出。

通常应该设置编码为base64。

方法 AddEmbeddedImage 添加了HTML的图片,这里的图片附件使用了base64编码。
方法 addAttachment 添加了邮件的附件。
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  joomla 对象 html web