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 添加了邮件的附件。
//获取对象与获取系统参数
$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 添加了邮件的附件。
相关文章推荐
- 如何在.NET 中简单使用SMTP发送邮件?
- JavaMail介绍及发送一封简单邮件
- Java Mail(二):JavaMail介绍及发送一封简单邮件
- How to send mail using C++ &amp;amp;amp; CAsyncSocket - SourceCode - 用C++ &amp;amp;amp; CAsyncSocket 如何发送邮件 - 源码 - HackerJLY
- 如何用编程的方式 在sharepoint里新建一个task后! 给 task 指定的人发送一封邮件!
- 利用Word的"邮件合并"功能,自动发送工资表邮件(亲自实践)
- How to send mail using VBScript & JMail - SourceCode - 如何用VBScript & JMail 发送邮件 - 源码
- Java Mail(二):JavaMail介绍及发送一封简单邮件
- 【java邮件】JavaMail介绍及发送一封简单邮件
- JavaMail-发送一封简单邮件(附带附件)
- 邮件发送中的"server does not support secure connection."
- java 简单邮件发送 & 常遇问题总结
- zen cart - 关闭zen cart的"tell a friend"发送邮件功能
- Java邮件开发(一):使用JMail发送一封简单邮件
- Java Mail(二):JavaMail介绍及发送一封简单邮件
- javaMal(二)-------如何通过java来发送简单的邮件
- Java Mail(二):JavaMail介绍及发送一封简单邮件
- Java Mail(二):JavaMail介绍及发送一封简单邮件
- 使用JavaMail发送一封简单的邮件
- Java Mail(二):JavaMail介绍及发送一封简单邮件