system/library/mail/swiftmailer.php
(完整代码) 2KB<?php
/**
* swiftmailer.php
*
* @copyright 2018 damicms.com - All Rights Reserved
* @link http://www.guangdawangluo.com
* @author Edward Yang <yangjin@damicms.com>
* @created 2018-05-23 10:01
* @modified 2018-05-23 10:01
*/
namespace Mail;
class SwiftMailer
{
public function send()
{
$security = '';
if ($this->smtp_port == 465) {
$security = 'ssl';
$this->smtp_hostname = str_replace(['ssl://', 'tls://'], '', $this->smtp_hostname);
} elseif ($this->smtp_port == 587) {
$security = 'tls';
$this->smtp_hostname = str_replace(['ssl://', 'tls://'], '', $this->smtp_hostname);
}
$options['ssl']['verify_peer'] = false;
$options['ssl']['verify_peer_name'] = false;
if ($this->originAdaptor == 'smtp') {
$transport = (new \Swift_SmtpTransport($this->smtp_hostname, $this->smtp_port, $security))
->setStreamOptions($options)
->setUsername($this->smtp_username)
->setPassword($this->smtp_password);
} elseif ($this->originAdaptor == 'mail') {
$transport = new \Swift_SendmailTransport('/usr/sbin/sendmail -bs');
} else {
throw new \Exception("Invalid adaptor {$this->originAdaptor} for SwiftMailer");
}
// Create the Mailer using your created Transport
$mailer = new \Swift_Mailer($transport);
// Create a message
$message = (new \Swift_Message($this->subject))
->setSender($this->from, $this->sender)
->setFrom([$this->from => $this->sender])
->setTo([$this->to])
->setReplyTo($this->reply_to);
if ($this->text) {
$message->setContentType("text/plain")->setBody($this->text);
} elseif ($this->html) {
$message->setContentType("text/html")->setBody($this->html);
}
// Send the message
$result = $mailer->send($message, $failures);
return ['result' => $result, 'failures' => $failures];
}
}
24 小时内免费解锁 3 个项目,之后 1 积分/个。 规则说明
AI 解读
登录后可用,每次 10 积分,解读结果公开显示在下面。
还没有人解读过这个文件。
