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,188건
+
제목 글쓴이 날짜 조회
06-08-18 조회 3,227
06-08-18 조회 2,895
06-08-18 조회 2,999
06-08-14 조회 2,444
06-08-13 조회 2,724
06-08-12 조회 3,862
06-08-12 조회 2,986
06-08-11 조회 4,212
06-08-11 조회 4,158
06-08-10 조회 3,263
06-08-10 조회 2,835
06-08-09 조회 3,887
06-08-08 조회 3,893
06-08-08 조회 5,142
06-08-08 조회 2,998
06-08-07 조회 3,745
06-08-06 조회 3,368
06-08-06 조회 4,502
06-08-05 조회 2,449
06-08-05 조회 2,530
06-08-05 조회 2,809
06-08-05 조회 3,285
06-08-05 조회 2,843
06-08-05 조회 2,777
06-08-04 조회 3,149
06-08-04 조회 3,282
06-08-04 조회 5,982
06-08-04 조회 3,388
06-08-04 조회 4,235
06-08-04 조회 3,688
06-08-03 조회 3,463
06-08-01 조회 5,737
06-07-31 조회 3,583
06-07-31 조회 3,422
06-07-30 조회 2,964
06-07-30 조회 2,756
06-07-29 조회 4,447
06-07-29 조회 3,395
06-07-28 조회 7,213
06-07-27 조회 3,154
06-07-26 조회 2,910
06-07-26 조회 3,785
06-07-26 조회 2,830
06-07-26 조회 3,312
06-07-25 조회 3,191
06-07-25 조회 4,613
06-07-25 조회 3,564
06-07-25 조회 3,777
06-07-24 조회 5,438
06-07-24 조회 4,667
06-07-23 조회 3,363
06-07-23 조회 5,455
06-07-22 조회 4,396
06-07-21 조회 5,213
06-07-21 조회 3,039
06-07-21 조회 3,243
06-07-21 조회 3,206
06-07-20 조회 4,364
06-07-20 조회 3,767
06-07-20 조회 4,523
06-07-20 조회 3,750
06-07-20 조회 3,581
06-07-20 조회 3,442
06-07-20 조회 3,288
06-07-20 조회 3,210
06-07-20 조회 5,332
06-07-20 조회 3,734
06-07-20 조회 3,267
06-07-20 조회 3,302
06-07-20 조회 3,898
06-07-19 조회 3,003
06-07-19 조회 4,337
06-07-19 조회 3,888
06-07-19 조회 3,353
06-07-19 조회 2,853
06-07-19 조회 3,268
06-07-19 조회 3,103
06-07-19 조회 2,960
06-07-19 조회 3,518
06-07-19 조회 3,357
06-07-19 조회 4,925
06-07-19 조회 4,795
06-07-19 조회 3,315
06-07-19 조회 4,320
06-07-19 조회 3,028
06-07-19 조회 3,448
06-07-19 조회 3,385
06-07-17 조회 3,393
06-07-17 조회 3,222
06-07-16 조회 3,821
06-07-14 조회 3,874
06-07-14 조회 4,273
06-07-14 조회 4,133
06-07-14 조회 3,735
06-07-13 조회 4,028
06-07-13 조회 4,215
06-07-12 조회 3,960
06-07-11 조회 3,660
06-07-11 조회 3,958
06-07-11 조회 5,590