D

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

· 2006-07-22 (토) 01:21:39 · 4354
출처: 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건
+
제목 글쓴이 날짜 조회
08-04-17 조회 4,339
08-03-14 조회 3,214
08-03-08 조회 3,036
08-03-06 조회 3,014
08-03-03 조회 4,303
08-02-20 조회 2,982
08-02-15 조회 3,902
08-02-11 조회 5,056
08-02-09 조회 5,797
08-02-05 조회 3,830
08-01-14 조회 6,642
08-01-11 조회 7,072
08-01-04 조회 1.1만
07-12-10 조회 4,978
07-12-10 조회 3,846
07-12-04 조회 3,383
07-11-29 조회 3,558
07-11-27 조회 3,917
07-11-23 조회 4,511
07-11-23 조회 4,246
07-11-13 조회 4,373
07-10-19 조회 4,838
07-10-17 조회 5,885
07-10-03 조회 5,047
07-10-02 조회 8,814
07-10-02 조회 4,466
07-09-09 조회 3,443
07-07-29 조회 4,326
07-07-28 조회 4,549
07-07-26 조회 4,453
07-06-19 조회 1.1만
07-06-17 조회 3,618
07-06-15 조회 4,111
07-05-31 조회 3,177
07-05-09 조회 5,330
07-05-04 조회 3,179
07-05-04 조회 3,525
07-04-28 조회 6,420
07-04-26 조회 4,668
07-04-14 조회 5,314
07-04-13 조회 3,728
07-04-12 조회 5,919
07-03-27 조회 3,861
07-03-19 조회 3,562
07-03-13 조회 4,633
07-03-07 조회 4,780
07-03-07 조회 3,294
07-02-25 조회 3,653
07-02-21 조회 4,544
07-02-18 조회 5,065
07-02-12 조회 3,412
07-02-02 조회 4,529
07-01-28 조회 6,143
07-01-27 조회 5,648
07-01-25 조회 4,011
07-01-21 조회 4,645
07-01-19 조회 6,584
07-01-19 조회 8,044
07-01-13 조회 3,503
07-01-09 조회 5,145
06-12-27 조회 3,539
06-11-24 조회 3,665
06-11-18 조회 4,180
06-10-17 조회 5,501
06-10-01 조회 4,422
06-09-26 조회 4,306
06-09-25 조회 4,629
06-09-25 조회 4,337
06-09-22 조회 4,866
06-09-22 조회 3,639
06-09-22 조회 4,474
06-09-13 조회 5,299
06-08-27 조회 4,901
06-08-26 조회 6,273
06-08-26 조회 5,581
06-08-23 조회 5,082
06-07-28 조회 7,180
06-07-24 조회 4,637
06-07-23 조회 5,417
06-07-21 조회 5,176
06-07-19 조회 3,060
06-07-19 조회 2,980
06-07-11 조회 3,629
06-07-11 조회 3,922
06-07-11 조회 4,501
06-07-11 조회 4,963
06-07-11 조회 3,580
06-07-11 조회 9,206
06-07-11 조회 4,062
06-07-11 조회 3,292
06-07-11 조회 3,342
06-07-11 조회 3,277
06-07-11 조회 3,079
06-07-07 조회 4,121
06-06-25 조회 4,471
06-06-15 조회 4,466
06-06-14 조회 4,948
06-06-11 조회 3,541
06-06-10 조회 3,921
06-06-09 조회 3,501