구글 메일(GMail)로 메일 발송하기 > 서버관리 Tip

본문 바로가기
 

구글 메일(GMail)로 메일 발송하기

페이지 정보

작성자 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 댓글 0건 조회 14,455회 작성일 09-05-19 19:01

본문

구글 메일(GMail)로 메일 발송하기
2006-10-09 21:27:23
메일 발송에 대해선 포탈에 IP를 등록한다는 둥 서버이름을 제대로 써야한다는 둥 말도 많고 탈도 많은데요, 메일서버를 구비하지 않고도 구글 메일을 이용해서 메일을 발송할 수 있습니다.

엄청난 뒷북일 수도 있지만, 검색해보니 없네요 :-)

급조한 소스 들어갑니다. 간단하기 때문에 딱 보시면 알듯 하구요, 중요한 것은 구글의 SMTP 메일 설정 몇가지 일듯 합니다.

우선 문자셋 기준은 UTF-8로 되어 있고, 예제로 만든 페이지에서 구글 광고를 삭제한 원본 그대로입니다.

원래 메일러를 PEAR로 쓰려 했는데 의존성이 있어서, XPertMailer라는 것을 사용했습니다. 말 그대로 전문가들이 쓰는 것이라는 뜻인 듯 하지만, 꽤나 편하게 쓸 수 있도록 되어 있더군요. XPertMailer.php 파일을 동일 폴더에 넣으면 작동할 것 같네요.

아참, 그리고 서버에 SSL 모듈이 깔려있어야 합니다.

--------------------------------------

if(isset($_POST['submit'])) {
    $password =    $_POST['password'];
    $sender_email =    $_POST['sender_email'];
    $sender =    '=?UTF-8?B?'.base64_encode($_POST['sender']).'?=';
    $receiver =    '"'.'=?UTF-8?B?'.base64_encode($_POST['receiver']).'?='.'" <'.$_POST['receiver_email'].'>';
    $subject =    '=?UTF-8?B?'.base64_encode($_POST['subject']).'?=';
    $contents =    $_POST['contents'];
    $contents .= '


----------------------
이 메일은 리플넷에서 제공하는 구글 SMTP를 이용한 시험 메일 발송입니다.
자세한 사항은 어바웃웹을 참고하세요.
http://blog.repl.net/web/
smtp/" target=_blank>http://www.repl.net/smtp/
    ';
    require("XPertMailer.php");
    $mail = new XPertMailer(SMTP_RELAY_CLIENT, '66.249.93.109', 1, true);
    $mail->auth($sender_email, $password, AUTH_LOGIN, SSL_TRUE, 465);
    //$mail->port(25);
    $mail->timeout(10);
    $mail->priority(P_HIGH);
    $mail->from($sender_email, $sender);
    $header['Reply-To'] = $sender_email;
    $header['X-Whatever'] = 'description';
    $mail->headers($header);
    $html = '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
    <html>
    <body>
'.nl2br($contents).'
    </body>
    </html>';
    $text    =    $contents;
    $send = $mail->send($receiver, $subject, $text, $html, 'UTF-8');
    echo $send ? "Done." : "Error.";
    echo "<br>Server response: ".$mail->response;
    if($send=="Done.") {
?>
<script>
alert('Success');
document.location = 'smtp/';" target=_blank>http://www.repl.net/smtp/';
</script>
<?PHP
    exit;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>구글의 SMTP 서버를 이용한 메일 발송</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<META NAME="Author" CONTENT="이삼구">
<META NAME="Keywords" CONTENT="지메일 SMTP 메일발송">
<META NAME="Description" CONTENT="구글의 지메일 SMTP를 이용한 메일발송 테스트 페이지입니다.">
</head>
<body style="margin: 0 0 0 0px"><script type="text/javascript" src="http://www.repl.net/js/repl_top.js"></script>

<div align=center>
<h1 style="font-size: 40px; font-family: 돋움">구글메일의 SMTP를 이용한 메일발송 <th>Beta!</th></h1>
아래의 정보를 정확히 넣고 발송 버튼을 눌러주세요.<br />
(보내는 메일은 실제 구글 메일이어야 합니다. 정확한 계정과 비밀번호를 넣으세요.)
<br /><br />
<form action="" method="POST">
보내는 이름 : <input type="text" name="sender" value="<?PHP echo @$_POST['sender'];?>" style="width: 450px;"><br />
구글 이메일 : <input type="text" name="sender_email" value="<?PHP echo @$_POST['sender_email'];?>" style="width: 450px;"><br />
구글 계정 암호 : <input type="password" name="password" value="<?PHP echo @$_POST['password'];?>" style="width: 450px;"><br />
받는 이름 : <input type="text" name="receiver" value="<?PHP echo @$_POST['receiver'];?>" style="width: 450px;"><br />
받는 이메일 : <input type="text" name="receiver_email" value="<?PHP echo @$_POST['receiver_email'];?>" style="width: 450px;"><br />

제목 : <input type="text" name="subject" value="<?PHP echo @$_POST['subject'];?>" style="width: 450px;"><br />
내용 : <textarea name="contents" style="width: 450px; height: 200px"><?PHP echo @$_POST['contents'];?></textarea><br />
<input type="submit" name="submit" value="발송">
</form><br /><br />
Copyright © 2006 <a href="http://www.repl.net/">리플넷</a>
</div>
</body>
</html>
구글 메일(GMail)로 메일 발송하기 2006-10-09 21:27:23
 
지앙춘윈
 http://kurapa.com/content-a696
 
메일 발송에 대해선 포탈에 IP를 등록한다는 둥 서버이름을 제대로 써야한다는 둥 말도 많고 탈도 많은데요, 메일서버를 구비하지 않고도 구글 메일을 이용해서 메일을 발송할 수 있습니다.
엄청난 뒷북일 수도 있지만, 검색해보니 없네요 :-)
급조한 소스 들어갑니다. 간단하기 때문에 딱 보시면 알듯 하구요, 중요한 것은 구글의 SMTP 메일 설정 몇가지 일듯 합니다.
우선 문자셋 기준은 UTF-8로 되어 있고, 예제로 만든 페이지에서 구글 광고를 삭제한 원본 그대로입니다.
원래 메일러를 PEAR로 쓰려 했는데 의존성이 있어서, XPertMailer라는 것을 사용했습니다. 말 그대로 전문가들이 쓰는 것이라는 뜻인 듯 하지만, 꽤나 편하게 쓸 수 있도록 되어 있더군요. XPertMailer.php 파일을 동일 폴더에 넣으면 작동할 것 같네요.
아참, 그리고 서버에 SSL 모듈이 깔려있어야 합니다.
--------------------------------------
if(isset($_POST['submit'])) {
    $password =    $_POST['password'];
    $sender_email =    $_POST['sender_email'];
    $sender =    '=?UTF-8?B?'.base64_encode($_POST['sender']).'?=';
    $receiver =    '"'.'=?UTF-8?B?'.base64_encode($_POST['receiver']).'?='.'" <'.$_POST['receiver_email'].'>';
    $subject =    '=?UTF-8?B?'.base64_encode($_POST['subject']).'?=';
    $contents =    $_POST['contents'];
    $contents .= '

----------------------
이 메일은 리플넷에서 제공하는 구글 SMTP를 이용한 시험 메일 발송입니다.
자세한 사항은 어바웃웹을 참고하세요.
http://blog.repl.net/web/
smtp/" target=_blank>http://www.repl.net/smtp/
    ';
    require("XPertMailer.php");
    $mail = new XPertMailer(SMTP_RELAY_CLIENT, '66.249.93.109', 1, true);
    $mail->auth($sender_email, $password, AUTH_LOGIN, SSL_TRUE, 465);
    //$mail->port(25);
    $mail->timeout(10);
    $mail->priority(P_HIGH);
    $mail->from($sender_email, $sender);
    $header['Reply-To'] = $sender_email;
    $header['X-Whatever'] = 'description';
    $mail->headers($header);
    $html = '<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.0 Transitional//EN\">
    <html>
    <body>
'.nl2br($contents).'
    </body>
    </html>';
    $text    =    $contents;
    $send = $mail->send($receiver, $subject, $text, $html, 'UTF-8');
    echo $send ? "Done." : "Error.";
    echo "<br>Server response: ".$mail->response;
    if($send=="Done.") {
?>
<script>
alert('Success');
document.location = 'smtp/';" target=_blank>http://www.repl.net/smtp/';
</script>
<?PHP
    exit;
    }
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>구글의 SMTP 서버를 이용한 메일 발송</title>
<meta http-equiv="Content-Style-Type" content="text/css" />
<META NAME="Author" CONTENT="이삼구">
<META NAME="Keywords" CONTENT="지메일 SMTP 메일발송">
<META NAME="Description" CONTENT="구글의 지메일 SMTP를 이용한 메일발송 테스트 페이지입니다.">
</head>
<body style="margin: 0 0 0 0px"><script type="text/javascript" src="http://www.repl.net/js/repl_top.js"></script>
<div align=center>
<h1 style="font-size: 40px; font-family: 돋움">구글메일의 SMTP를 이용한 메일발송 <th>Beta!</th></h1>
아래의 정보를 정확히 넣고 발송 버튼을 눌러주세요.<br />
(보내는 메일은 실제 구글 메일이어야 합니다. 정확한 계정과 비밀번호를 넣으세요.)
<br /><br />
<form action="" method="POST">
보내는 이름 : <input type="text" name="sender" value="<?PHP echo @$_POST['sender'];?>" style="width: 450px;"><br />
구글 이메일 : <input type="text" name="sender_email" value="<?PHP echo @$_POST['sender_email'];?>" style="width: 450px;"><br />
구글 계정 암호 : <input type="password" name="password" value="<?PHP echo @$_POST['password'];?>" style="width: 450px;"><br />
받는 이름 : <input type="text" name="receiver" value="<?PHP echo @$_POST['receiver'];?>" style="width: 450px;"><br />
받는 이메일 : <input type="text" name="receiver_email" value="<?PHP echo @$_POST['receiver_email'];?>" style="width: 450px;"><br />
제목 : <input type="text" name="subject" value="<?PHP echo @$_POST['subject'];?>" style="width: 450px;"><br />
내용 : <textarea name="contents" style="width: 450px; height: 200px"><?PHP echo @$_POST['contents'];?></textarea><br />
<input type="submit" name="submit" value="발송">
</form><br /><br />
Copyright © 2006 <a href="http://www.repl.net/">리플넷</a>
</div>
</body>
</html> 

댓글목록

등록된 댓글이 없습니다.

Total 159건 8 페이지
서버관리 Tip 목록
번호 제목 글쓴이 조회 날짜
33 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 16344 05-19
32 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15643 05-19
31 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15445 05-19
30 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15158 05-19
29 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14803 05-19
28 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15674 05-19
27 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 11619 05-19
26 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14585 05-19
25 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14900 05-19
24 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14346 05-19
23 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 13857 05-19
열람중 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 14456 05-19
21 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 16441 04-17
20 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 10879 01-26
19 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 9224 01-23
18 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 9191 12-10
17 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 15079 11-02
16 no_profile 차동박 쪽지보내기 메일보내기 홈페이지 자기소개 아이디로 검색 전체게시물 12277 10-20
게시물 검색