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,433
19년 전 조회 1,686
19년 전 조회 2,828
19년 전 조회 1,941
19년 전 조회 3,213
19년 전 조회 3,124
19년 전 조회 2,233
19년 전 조회 1,780
19년 전 조회 2,827
19년 전 조회 2,894
19년 전 조회 4,006
19년 전 조회 1,970
19년 전 조회 2,620
19년 전 조회 2,331
19년 전 조회 3,460
19년 전 조회 1,417
19년 전 조회 1,481
19년 전 조회 1,762
19년 전 조회 2,204
19년 전 조회 1,832
19년 전 조회 1,692
19년 전 조회 2,102
19년 전 조회 2,199
19년 전 조회 4,955
19년 전 조회 2,325
19년 전 조회 3,192
19년 전 조회 2,640
19년 전 조회 2,405
19년 전 조회 4,696
19년 전 조회 2,552
19년 전 조회 2,401
19년 전 조회 1,940
19년 전 조회 1,721
19년 전 조회 3,346
19년 전 조회 2,319
19년 전 조회 6,150
19년 전 조회 2,012
19년 전 조회 1,895
19년 전 조회 2,697
19년 전 조회 1,797
19년 전 조회 2,272
19년 전 조회 2,102
19년 전 조회 3,550
19년 전 조회 2,569
19년 전 조회 2,740
19년 전 조회 4,362
19년 전 조회 3,541
19년 전 조회 2,303
19년 전 조회 4,290
19년 전 조회 3,263
19년 전 조회 4,128
19년 전 조회 1,990
19년 전 조회 2,205
19년 전 조회 2,134
19년 전 조회 3,338
19년 전 조회 2,710
19년 전 조회 3,499
19년 전 조회 2,674
19년 전 조회 2,513
19년 전 조회 2,336
19년 전 조회 2,229
19년 전 조회 2,118
19년 전 조회 4,244
19년 전 조회 2,666
19년 전 조회 2,154
19년 전 조회 2,252
19년 전 조회 2,835
19년 전 조회 1,951
19년 전 조회 3,192
19년 전 조회 2,750
19년 전 조회 2,259
19년 전 조회 1,804
19년 전 조회 2,229
19년 전 조회 1,999
19년 전 조회 1,894
19년 전 조회 2,456
19년 전 조회 2,312
19년 전 조회 3,877
19년 전 조회 3,732
19년 전 조회 2,232
19년 전 조회 3,275
19년 전 조회 1,948
19년 전 조회 2,374
19년 전 조회 2,267
19년 전 조회 2,335
19년 전 조회 2,170
19년 전 조회 2,804
19년 전 조회 2,813
19년 전 조회 3,160
19년 전 조회 3,030
19년 전 조회 2,700
19년 전 조회 2,918
19년 전 조회 3,167
19년 전 조회 2,868
19년 전 조회 2,605
19년 전 조회 2,915
19년 전 조회 4,495
19년 전 조회 2,420
19년 전 조회 2,438
19년 전 조회 3,475
🐛 버그신고