D

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

· 2006-07-22 (토) 01:21:39 · 4327
출처: 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,308
08-03-14 조회 3,200
08-03-08 조회 3,021
08-03-06 조회 2,991
08-03-03 조회 4,283
08-02-20 조회 2,966
08-02-15 조회 3,882
08-02-11 조회 5,039
08-02-09 조회 5,739
08-02-05 조회 3,814
08-01-14 조회 6,627
08-01-11 조회 7,058
08-01-04 조회 1.1만
07-12-10 조회 4,962
07-12-10 조회 3,824
07-12-04 조회 3,369
07-11-29 조회 3,545
07-11-27 조회 3,901
07-11-23 조회 4,502
07-11-23 조회 4,230
07-11-13 조회 4,358
07-10-19 조회 4,815
07-10-17 조회 5,871
07-10-03 조회 4,923
07-10-02 조회 8,793
07-10-02 조회 4,451
07-09-09 조회 3,416
07-07-29 조회 4,302
07-07-28 조회 4,533
07-07-26 조회 4,436
07-06-19 조회 1.1만
07-06-17 조회 3,601
07-06-15 조회 4,099
07-05-31 조회 3,155
07-05-09 조회 5,313
07-05-04 조회 3,162
07-05-04 조회 3,510
07-04-28 조회 6,405
07-04-26 조회 4,647
07-04-14 조회 5,294
07-04-13 조회 3,712
07-04-12 조회 5,904
07-03-27 조회 3,843
07-03-19 조회 3,526
07-03-13 조회 4,614
07-03-07 조회 4,769
07-03-07 조회 3,279
07-02-25 조회 3,637
07-02-21 조회 4,527
07-02-18 조회 5,046
07-02-12 조회 3,389
07-02-02 조회 4,508
07-01-28 조회 6,119
07-01-27 조회 5,626
07-01-25 조회 3,989
07-01-21 조회 4,625
07-01-19 조회 6,570
07-01-19 조회 8,026
07-01-13 조회 3,482
07-01-09 조회 5,118
06-12-27 조회 3,523
06-11-24 조회 3,641
06-11-18 조회 4,158
06-10-17 조회 5,477
06-10-01 조회 4,397
06-09-26 조회 4,283
06-09-25 조회 4,606
06-09-25 조회 4,308
06-09-22 조회 4,848
06-09-22 조회 3,620
06-09-22 조회 4,443
06-09-13 조회 5,280
06-08-27 조회 4,883
06-08-26 조회 6,255
06-08-26 조회 5,568
06-08-23 조회 5,062
06-07-28 조회 7,163
06-07-24 조회 4,615
06-07-23 조회 5,399
06-07-21 조회 5,161
06-07-19 조회 3,040
06-07-19 조회 2,951
06-07-11 조회 3,610
06-07-11 조회 3,907
06-07-11 조회 4,474
06-07-11 조회 4,938
06-07-11 조회 3,565
06-07-11 조회 9,187
06-07-11 조회 4,048
06-07-11 조회 3,280
06-07-11 조회 3,330
06-07-11 조회 3,256
06-07-11 조회 3,057
06-07-07 조회 4,100
06-06-25 조회 4,455
06-06-15 조회 4,446
06-06-14 조회 4,940
06-06-11 조회 3,518
06-06-10 조회 3,900
06-06-09 조회 3,482