링크
https://www.phpschool.com/gnuboard4/bbs/board.php?bo_table=qna_install&wr_id=119260#c_119268 (206) https://gist.github.com/anonymous/a741c28e79a09fc8dd88b267527c75a7 (182)
옆동네서 그누보드에서 메일건(mialgun) 발송 오류에 대해 답변한 내용입니다.
요즘 많이 쓰는 솔루션이니 참고가 될까 하고 소스를 올립니다.
한달 1만건 까지 발송이 무료입니다.(신용카드는 연결해두어야 합니다.)
<?php
class MailgunMailer {
const CRLF = "\r\n";
const DEFAULT_CHARSET = "utf-8";
private $Charset = "utf-8";
private $api_key = "메일건 api key"; //mailgun domain api-key
private $api_call_url = "https://api.mailgun.net/v3/your.domain.com/messages";
private $From = "관리자 <admin@your.domain.com>";
private $To = "";
private $Cc = "";
private $Bcc = "";
private $Subject = "";
private $Content = "";
private $Type = 0;
private $File = null;
private $attachement = null;
public function __construct() {
global $g4;
if($g4['charset'] == "euc-kr") {
$this->Charset = "euc-kr";
}
}
public function setCharset($charset) {
$this->Charset = strtolower($charset);
}
public function setFrom($from) {
if($this->Charset == "euc-kr") {
$this->From = iconv("euc-kr", "utf-8", $from);
} else {
$this->From = $from;
}
}
public function setTo($to) {
$this->To = $to;
}
public function setSubject($subject) {
$this->Subject = $subject;
}
public function setContent($content) {
$this->Content = $content;
}
public function setType($type) {
$this->Type = $type;
}
public function attachFile($file) {
$this->attachement = $file;
}
public function send() {
if($this->Charset == "euc-kr") {
$this->To = iconv("euc-kr", "utf-8", $this->To);
$this->Subject = iconv("euc-kr", "utf-8", $this->Subject);
$this->Content = iconv("euc-kr", "utf-8", $this->Content);
}
$post = [
'from' => $this->From,
'to' => $this->To,
'subject' => $this->Subject,
];
if($this->Type) {
$post['html'] = $this->Content;
} else {
$post['text'] = $this->Content;
}
$ch = curl_init($this->api_call_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $this->api_key);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
return $response;
}
/**
*
* @param type 메일 본문 내용이 html인지 여부 0:text, 1:html
*/
function mailer($to, $subject, $content, $type=0, $file="", $cc="", $bcc="") {
global $g4;
$this->setCharset($g4['charset']);
$this->setTo($to);
$this->setSubject($subject);
$this->setContent($content);
$this->setType($type);
$this->send();
}
}
?>
사용예제
$xmailer = new MailgunMailer();
$xmailer->setCharset($g4['charset']);
if($fname) {
$xmailer->setFrom("$fname <{$fmail}>");
} else {
$xmailer->setFrom($fmail);
}
$xmailer->setTo($to);
$xmailer->setSubject($subject);
$xmailer->setContent($content);
$xmailer->setType($type);
$response = $xmailer->send();
그누보드의 경우 mailer.lib.php 에서 위의 코드로 대체하시면 됩니다.
요즘 많이 쓰는 솔루션이니 참고가 될까 하고 소스를 올립니다.
한달 1만건 까지 발송이 무료입니다.(신용카드는 연결해두어야 합니다.)
<?php
class MailgunMailer {
const CRLF = "\r\n";
const DEFAULT_CHARSET = "utf-8";
private $Charset = "utf-8";
private $api_key = "메일건 api key"; //mailgun domain api-key
private $api_call_url = "https://api.mailgun.net/v3/your.domain.com/messages";
private $From = "관리자 <admin@your.domain.com>";
private $To = "";
private $Cc = "";
private $Bcc = "";
private $Subject = "";
private $Content = "";
private $Type = 0;
private $File = null;
private $attachement = null;
public function __construct() {
global $g4;
if($g4['charset'] == "euc-kr") {
$this->Charset = "euc-kr";
}
}
public function setCharset($charset) {
$this->Charset = strtolower($charset);
}
public function setFrom($from) {
if($this->Charset == "euc-kr") {
$this->From = iconv("euc-kr", "utf-8", $from);
} else {
$this->From = $from;
}
}
public function setTo($to) {
$this->To = $to;
}
public function setSubject($subject) {
$this->Subject = $subject;
}
public function setContent($content) {
$this->Content = $content;
}
public function setType($type) {
$this->Type = $type;
}
public function attachFile($file) {
$this->attachement = $file;
}
public function send() {
if($this->Charset == "euc-kr") {
$this->To = iconv("euc-kr", "utf-8", $this->To);
$this->Subject = iconv("euc-kr", "utf-8", $this->Subject);
$this->Content = iconv("euc-kr", "utf-8", $this->Content);
}
$post = [
'from' => $this->From,
'to' => $this->To,
'subject' => $this->Subject,
];
if($this->Type) {
$post['html'] = $this->Content;
} else {
$post['text'] = $this->Content;
}
$ch = curl_init($this->api_call_url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_USERPWD, $this->api_key);
curl_setopt($ch, CURLOPT_POSTFIELDS, $post);
// execute!
$response = curl_exec($ch);
// close the connection, release resources used
curl_close($ch);
return $response;
}
/**
*
* @param type 메일 본문 내용이 html인지 여부 0:text, 1:html
*/
function mailer($to, $subject, $content, $type=0, $file="", $cc="", $bcc="") {
global $g4;
$this->setCharset($g4['charset']);
$this->setTo($to);
$this->setSubject($subject);
$this->setContent($content);
$this->setType($type);
$this->send();
}
}
?>
사용예제
$xmailer = new MailgunMailer();
$xmailer->setCharset($g4['charset']);
if($fname) {
$xmailer->setFrom("$fname <{$fmail}>");
} else {
$xmailer->setFrom($fmail);
}
$xmailer->setTo($to);
$xmailer->setSubject($subject);
$xmailer->setContent($content);
$xmailer->setType($type);
$response = $xmailer->send();
그누보드의 경우 mailer.lib.php 에서 위의 코드로 대체하시면 됩니다.
댓글 6개
게시글 목록
| 번호 | 제목 |
|---|---|
| 507 | |
| 504 | |
| 502 | |
| 499 | |
| 495 | |
| 492 | |
| 485 | |
| 484 | |
| 481 | |
| 480 | |
| 478 | |
| 476 | |
| 467 | |
| 462 | |
| 459 | |
| 458 | |
| 457 | |
| 452 | |
| 444 | |
| 438 | |
| 437 | |
| 425 | |
| 423 | |
| 420 | |
| 417 | |
| 416 | |
| 415 | |
| 410 | |
| 407 | |
| 405 |
댓글 작성
댓글을 작성하시려면 로그인이 필요합니다.
로그인하기