D

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

· 2006-07-22 (토) 01:21:39 · 4326
출처: 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-12-15 조회 4,412
06-12-15 조회 2,830
06-12-15 조회 3,139
06-12-15 조회 2,989
06-12-15 조회 2,925
06-12-15 조회 2,709
06-12-15 조회 4,356
06-12-15 조회 2,818
06-12-15 조회 2,981
06-12-15 조회 2,606
06-12-15 조회 3,257
06-12-15 조회 3,504
06-12-15 조회 2,758
06-12-15 조회 2,905
06-12-12 조회 3,259
06-12-11 조회 4,378
06-12-10 조회 4,032
06-12-07 조회 3,546
06-12-07 조회 3,836
06-11-30 조회 3,100
06-11-27 조회 5,440
06-11-11 조회 3,135
06-10-16 조회 3,640
06-10-10 조회 3,345
06-09-27 조회 8,979
06-09-26 조회 4,116
06-09-21 조회 3,776
06-09-21 조회 3,394
06-09-21 조회 4,257
06-09-21 조회 4,217
06-09-21 조회 3,552
06-09-21 조회 3,758
06-09-21 조회 3,608
06-09-21 조회 4,364
06-09-21 조회 4,551
06-09-18 조회 3,466
06-09-15 조회 3,482
06-09-15 조회 3,315
06-09-11 조회 3,613
06-09-11 조회 3,367
06-09-11 조회 3,576
06-09-11 조회 4,927
06-09-11 조회 4,438
06-09-06 조회 3,061
06-09-04 조회 3,813
06-09-02 조회 3,999
06-09-01 조회 4,093
06-08-28 조회 4,288
06-08-27 조회 3,333
06-08-27 조회 2,670
06-08-27 조회 2,569
06-08-27 조회 3,195
06-08-27 조회 2,862
06-08-27 조회 2,910
06-08-27 조회 6,317
06-08-27 조회 2,521
06-08-27 조회 2,448
06-08-24 조회 4,647
06-08-23 조회 2,904
06-08-22 조회 2,854
06-08-22 조회 2,809
06-08-19 조회 2,957
06-08-12 조회 2,923
06-08-11 조회 4,169
06-08-08 조회 2,961
06-08-06 조회 3,315
06-08-05 조회 2,751
06-08-04 조회 3,227
06-08-04 조회 4,196
06-08-03 조회 3,406
06-07-25 조회 3,520
06-07-23 조회 3,277
06-07-22 조회 4,327
06-07-21 조회 2,973
06-07-21 조회 3,187
06-07-21 조회 3,147
06-07-20 조회 4,479
06-07-20 조회 5,266
06-07-20 조회 3,829
06-07-19 조회 4,290
06-07-19 조회 3,209
06-07-19 조회 4,863
06-07-19 조회 4,247
06-07-19 조회 3,374
06-07-12 조회 3,903
06-07-11 조회 5,538
06-07-11 조회 4,196
06-07-11 조회 2,730
06-07-11 조회 4,389
06-07-11 조회 3,511
06-07-11 조회 3,749
06-07-11 조회 2,889
06-07-11 조회 2,787
06-07-11 조회 3,479
06-06-27 조회 4,546
06-06-21 조회 4,225
06-06-15 조회 3,903
06-06-10 조회 3,339
06-06-05 조회 3,136
06-05-31 조회 4,217