Skip to content

Commit

Permalink
fix mail config
Browse files Browse the repository at this point in the history
  • Loading branch information
orvice committed Jan 17, 2016
1 parent 7094da8 commit 8a06a5b
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 4 deletions.
16 changes: 14 additions & 2 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ baseUrl = 'https://www.google.com' // 站点地址
timeZone = 'PRC' // RPC 天朝时间 UTC 格林时间
pwdMethod = 'md5' // 密码加密 可选 md5,sha256
salt = '' // 密码加密用,从旧版升级请留空
theme' = 'default' // 主题
authDriver' = 'redis' // 登录验证存储方式,推荐使用Redis support cookie,redis
theme = 'default' // 主题
authDriver = 'redis' // 登录验证存储方式,推荐使用Redis 可选: cookie,redis

// 邮件
mailDriver = 'mailgun' // mailgun or smtp
Expand Down Expand Up @@ -37,3 +37,15 @@ redis_scheme = 'tcp'
redis_host = '127.0.0.1'
redis_port = '6379'
redis_database = '0'

# mailgun
mailgun_key = ''
mailgun_domain = ''
mailgun_sender = ''

# smtp
smtp_host = ''
smtp_username = ''
smtp_port = ''
smtp_name = ''
smtp_sender = ''
10 changes: 9 additions & 1 deletion app/Services/Mail/Mailgun.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,20 @@ class Mailgun
private $config,$mg,$domain,$sender;

public function __construct(){
$this->config = Config::get("mail")["mailgun"];
$this->config = $this->getConfig();
$this->mg = new MailgunService($this->config["key"]);
$this->domain = $this->config["domain"];
$this->sender = $this->config["sender"];
}

public function getConfig(){
return [
"key" => Config::get('mailgun_key'),
"domain" => Config::get('mailgun_domain'),
"sender" => Config::get('mailgun_sender')
];
}

public function send($to,$subject,$text){
$this->mg->sendMessage($this->domain, array('from' => $this->sender,
'to' => $to,
Expand Down
12 changes: 11 additions & 1 deletion app/Services/Mail/Smtp.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Smtp
private $mail,$config;

public function __construct(){
$this->config = Config::get("mail")["smtp"];
$this->config = $this->getConfig();
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
Expand All @@ -26,6 +26,16 @@ public function __construct(){
$this->mail = $mail;
}

public function getConfig(){
return [
"host" => Config::get('smtp_host'),
"username" => Config::get('smtp_username'),
"port" => Config::get('smtp_port'),
"sender" => Config::get('smtp_sender'),
"name" => Config::get('smtp_name')
];
}

public function send($to,$subject,$text){
$mail = $this->mail;
$mail->addAddress($to); // Add a recipient
Expand Down

0 comments on commit 8a06a5b

Please sign in to comment.