D

[소개] smtp를 이용하여 mail 보내기

· 2006-07-22 (토) 01:21:39 · 4343
출처: http://www.linuxquestions.org/questions/showthread.php?t=359033
http://pear.php.net/package/Mail
아래 소스는
http://www.linuxquestions.org/questions/showthread.php?t=359033
에서 가져 왔고
Mail_smtp 클래스는
http://pear.php.net/package/Mail
에서 받으시면 됩니다.

<?php

include('Mail/smtp.php');

class MailHandler{
var $params = null;
var $mail_object = null;
var $recipients = null;
var $headers = null;
var $body = "";

function MailHandler($host, $port, $auth, $username, $password, $persist) {
$this->params["host"] = $host;
$this->params["port"] = $port;
$this->params["auth"] = $auth;
$this->params["username"] = $username;
$this->params["password"] = $password;
$this->params["persist"] = $persist;

// Create the mail object using the Mail::factory method
//$this->mail_object =& Mail::factory('smtp', $this->params);
$this->mail_object = new Mail_smtp($this->params);
}

function createFrom($email){
$this->headers['From'] = $email;
}

function createTo($email){
$this->headers['To'] = $email;
$this->recipients = array($email);
}

function createCC($email){
$this->headers['Cc'] = $email;
}

function createBCC($email){
$this->headers['Bcc'] = $email;
}

function createSubject($sub){
$this->headers['Subject'] = $sub;
}

function createBody($body){
$this->body=$body;
}

function sendMail(){
if ($this->mail_object->send($this->recipients, $this->headers, $this->body)) {
return true;
}
else{
return false;
}
}
}


$smtpserver_host = "localhost"; // The server to connect. Default is localhost
$smtpserver_Port = 25; // The port to connect. Default is 25
$smtpserver_auth = FALSE; // Whether or not to use SMTP authentication. Default is FALSE
$smtpserver_username = "username"; // The username to use for SMTP authentication.
$smtpserver_password = "password"; // The password to use for SMTP authentication.
$smtpserver_persist = FALSE; // Indicates whether or not the SMTP connection should persist over multiple calls to the send() method.
$mailhandler=new MailHandler($smtpserver_host, $smtpserver_Port, $smtpserver_auth, $smtpserver_username, $smtpserver_password, $smtpserver_persist);

$mailhandler->createTo("toaddress");
$mailhandler->createFrom("fromaddress");
$mailhandler->createSubject("subject");
$mailhandler->createBody("body");

if($mailhandler->sendMail()){
echo "Mail sent.\n";
}
else{
echo "Error sending mail!\n";
}

?><div class='small'>[이 게시물은 관리자님에 의해 2011-10-31 17:12:10 PHP & HTML에서 이동 됨]</div>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
06-08-18 조회 3,178
06-08-18 조회 2,841
06-08-18 조회 2,953
06-08-14 조회 2,395
06-08-13 조회 2,679
06-08-12 조회 3,808
06-08-12 조회 2,930
06-08-11 조회 4,177
06-08-11 조회 4,114
06-08-10 조회 3,208
06-08-10 조회 2,794
06-08-09 조회 3,853
06-08-08 조회 3,867
06-08-08 조회 5,113
06-08-08 조회 2,969
06-08-07 조회 3,689
06-08-06 조회 3,324
06-08-06 조회 4,469
06-08-05 조회 2,406
06-08-05 조회 2,477
06-08-05 조회 2,758
06-08-05 조회 3,244
06-08-05 조회 2,803
06-08-05 조회 2,741
06-08-04 조회 3,091
06-08-04 조회 3,237
06-08-04 조회 5,948
06-08-04 조회 3,350
06-08-04 조회 4,202
06-08-04 조회 3,634
06-08-03 조회 3,415
06-08-01 조회 5,698
06-07-31 조회 3,558
06-07-31 조회 3,388
06-07-30 조회 2,930
06-07-30 조회 2,721
06-07-29 조회 4,399
06-07-29 조회 3,350
06-07-28 조회 7,172
06-07-27 조회 3,116
06-07-26 조회 2,864
06-07-26 조회 3,741
06-07-26 조회 2,791
06-07-26 조회 3,261
06-07-25 조회 3,150
06-07-25 조회 4,555
06-07-25 조회 3,525
06-07-25 조회 3,740
06-07-24 조회 5,396
06-07-24 조회 4,630
06-07-23 조회 3,294
06-07-23 조회 5,412
06-07-22 조회 4,344
06-07-21 조회 5,171
06-07-21 조회 2,989
06-07-21 조회 3,197
06-07-21 조회 3,156
06-07-20 조회 4,327
06-07-20 조회 3,712
06-07-20 조회 4,488
06-07-20 조회 3,716
06-07-20 조회 3,537
06-07-20 조회 3,405
06-07-20 조회 3,249
06-07-20 조회 3,164
06-07-20 조회 5,279
06-07-20 조회 3,679
06-07-20 조회 3,223
06-07-20 조회 3,253
06-07-20 조회 3,841
06-07-19 조회 2,965
06-07-19 조회 4,301
06-07-19 조회 3,827
06-07-19 조회 3,306
06-07-19 조회 2,807
06-07-19 조회 3,219
06-07-19 조회 3,052
06-07-19 조회 2,892
06-07-19 조회 3,464
06-07-19 조회 3,298
06-07-19 조회 4,873
06-07-19 조회 4,739
06-07-19 조회 3,257
06-07-19 조회 4,264
06-07-19 조회 2,972
06-07-19 조회 3,392
06-07-19 조회 3,320
06-07-17 조회 3,342
06-07-17 조회 3,184
06-07-16 조회 3,791
06-07-14 조회 3,839
06-07-14 조회 4,221
06-07-14 조회 4,089
06-07-14 조회 3,687
06-07-13 조회 3,981
06-07-13 조회 4,164
06-07-12 조회 3,914
06-07-11 조회 3,625
06-07-11 조회 3,915
06-07-11 조회 5,545