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>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

+
제목 글쓴이 날짜 조회
19년 전 조회 1,590
19년 전 조회 1,840
19년 전 조회 2,990
19년 전 조회 2,103
19년 전 조회 3,362
19년 전 조회 3,282
19년 전 조회 2,389
19년 전 조회 1,942
19년 전 조회 2,978
19년 전 조회 3,039
19년 전 조회 4,170
19년 전 조회 2,137
19년 전 조회 2,787
19년 전 조회 2,487
19년 전 조회 3,622
19년 전 조회 1,571
19년 전 조회 1,627
19년 전 조회 1,918
19년 전 조회 2,365
19년 전 조회 1,984
19년 전 조회 1,862
19년 전 조회 2,255
19년 전 조회 2,349
19년 전 조회 5,109
19년 전 조회 2,492
19년 전 조회 3,348
19년 전 조회 2,808
19년 전 조회 2,568
19년 전 조회 4,849
19년 전 조회 2,711
19년 전 조회 2,557
19년 전 조회 2,104
19년 전 조회 1,895
19년 전 조회 3,499
19년 전 조회 2,473
19년 전 조회 6,313
19년 전 조회 2,175
19년 전 조회 2,060
19년 전 조회 2,857
19년 전 조회 1,959
19년 전 조회 2,428
19년 전 조회 2,260
19년 전 조회 3,708
19년 전 조회 2,714
19년 전 조회 2,900
19년 전 조회 4,520
19년 전 조회 3,695
19년 전 조회 2,462
19년 전 조회 4,456
19년 전 조회 3,426
19년 전 조회 4,291
19년 전 조회 2,161
19년 전 조회 2,358
19년 전 조회 2,297
19년 전 조회 3,498
19년 전 조회 2,867
19년 전 조회 3,654
19년 전 조회 2,826
19년 전 조회 2,658
19년 전 조회 2,495
19년 전 조회 2,387
19년 전 조회 2,276
19년 전 조회 4,407
19년 전 조회 2,825
19년 전 조회 2,302
19년 전 조회 2,407
19년 전 조회 2,986
19년 전 조회 2,104
19년 전 조회 3,350
19년 전 조회 2,905
19년 전 조회 2,414
19년 전 조회 1,944
19년 전 조회 2,392
19년 전 조회 2,166
19년 전 조회 2,042
19년 전 조회 2,610
19년 전 조회 2,463
19년 전 조회 4,037
19년 전 조회 3,893
19년 전 조회 2,397
19년 전 조회 3,437
19년 전 조회 2,102
19년 전 조회 2,531
19년 전 조회 2,419
19년 전 조회 2,486
19년 전 조회 2,329
19년 전 조회 2,962
19년 전 조회 2,970
19년 전 조회 3,312
19년 전 조회 3,179
19년 전 조회 2,845
19년 전 조회 3,067
19년 전 조회 3,308
19년 전 조회 3,024
19년 전 조회 2,754
19년 전 조회 3,080
19년 전 조회 4,659
19년 전 조회 2,563
19년 전 조회 2,587
19년 전 조회 3,637