D

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

출처: 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,187건
+
제목 글쓴이 날짜 조회
06-07-11 조회 3,550
06-07-11 조회 4,615
06-07-11 조회 4,329
06-07-11 조회 3,919
06-07-11 조회 3,135
06-07-11 조회 2,884
06-07-11 조회 3,996
06-07-11 조회 2,867
06-07-11 조회 3,446
06-07-11 조회 5,047
06-07-11 조회 4,836
06-07-11 조회 4,520
06-07-11 조회 4,521
06-07-11 조회 2,658
06-07-11 조회 3,014
06-07-11 조회 2,952
06-07-11 조회 3,637
06-07-11 조회 5,796
06-07-11 조회 3,863
06-07-11 조회 2,989
06-07-11 조회 3,000
06-07-11 조회 2,901
06-07-11 조회 3,663
06-07-11 조회 9,287
06-07-11 조회 3,801
06-07-11 조회 3,846
06-07-11 조회 4,132
06-07-11 조회 3,360
06-07-11 조회 3,410
06-07-11 조회 3,358
06-07-11 조회 3,155
06-07-11 조회 3,441
06-07-11 조회 3,571
06-07-07 조회 4,201
06-07-05 조회 3,384
06-07-05 조회 3,060
06-07-02 조회 3,911
06-06-29 조회 6,155
06-06-27 조회 4,658
06-06-25 조회 4,557
06-06-24 조회 4,062
06-06-24 조회 3,522
06-06-22 조회 2,600
06-06-21 조회 4,324
06-06-21 조회 3,139
06-06-19 조회 6,528
06-06-16 조회 3,497
06-06-15 조회 4,549
06-06-15 조회 4,012
06-06-14 조회 2,932
06-06-14 조회 5,032
06-06-14 조회 3,532
06-06-14 조회 3,375
06-06-13 조회 4,136
06-06-13 조회 4,464
06-06-13 조회 3,572
06-06-13 조회 3,374
06-06-13 조회 3,359
06-06-12 조회 3,074
06-06-12 조회 4,176
06-06-12 조회 3,137
06-06-12 조회 3,182
06-06-12 조회 2,805
06-06-12 조회 3,370
06-06-11 조회 3,281
06-06-11 조회 3,646
06-06-10 조회 4,019
06-06-10 조회 3,481
06-06-09 조회 3,615
06-06-09 조회 4,567
06-06-08 조회 4,382
06-06-08 조회 4,295
06-06-08 조회 4,141
06-06-08 조회 3,143
06-06-08 조회 3,474
06-06-08 조회 3,336
06-06-08 조회 3,125
06-06-08 조회 3,568
06-06-08 조회 3,460
06-06-08 조회 3,874
06-06-08 조회 3,250
06-06-08 조회 4,520
06-06-07 조회 3,050
06-06-07 조회 3,752
06-06-07 조회 2,677
06-06-05 조회 3,972
06-06-05 조회 4,151
06-06-05 조회 3,252
06-06-05 조회 3,112
06-06-02 조회 3,554
06-06-02 조회 3,593
06-06-01 조회 4,227
06-06-01 조회 7,894
06-06-01 조회 3,859
06-05-31 조회 4,337
06-05-31 조회 4,248
06-05-31 조회 3,049
06-05-31 조회 4,469
06-05-31 조회 3,328
06-05-30 조회 3,790