D

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

· 2006-07-22 (토) 01:21:39 · 4331
출처: 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,416
06-12-15 조회 2,835
06-12-15 조회 3,143
06-12-15 조회 2,991
06-12-15 조회 2,931
06-12-15 조회 2,716
06-12-15 조회 4,361
06-12-15 조회 2,826
06-12-15 조회 2,988
06-12-15 조회 2,615
06-12-15 조회 3,260
06-12-15 조회 3,510
06-12-15 조회 2,759
06-12-15 조회 2,908
06-12-12 조회 3,260
06-12-11 조회 4,384
06-12-10 조회 4,036
06-12-07 조회 3,548
06-12-07 조회 3,839
06-11-30 조회 3,105
06-11-27 조회 5,442
06-11-11 조회 3,139
06-10-16 조회 3,646
06-10-10 조회 3,349
06-09-27 조회 8,981
06-09-26 조회 4,123
06-09-21 조회 3,779
06-09-21 조회 3,397
06-09-21 조회 4,259
06-09-21 조회 4,219
06-09-21 조회 3,554
06-09-21 조회 3,762
06-09-21 조회 3,613
06-09-21 조회 4,368
06-09-21 조회 4,555
06-09-18 조회 3,475
06-09-15 조회 3,486
06-09-15 조회 3,317
06-09-11 조회 3,618
06-09-11 조회 3,370
06-09-11 조회 3,581
06-09-11 조회 4,939
06-09-11 조회 4,443
06-09-06 조회 3,062
06-09-04 조회 3,815
06-09-02 조회 4,002
06-09-01 조회 4,097
06-08-28 조회 4,293
06-08-27 조회 3,336
06-08-27 조회 2,671
06-08-27 조회 2,573
06-08-27 조회 3,197
06-08-27 조회 2,862
06-08-27 조회 2,913
06-08-27 조회 6,319
06-08-27 조회 2,525
06-08-27 조회 2,454
06-08-24 조회 4,652
06-08-23 조회 2,911
06-08-22 조회 2,857
06-08-22 조회 2,815
06-08-19 조회 2,962
06-08-12 조회 2,926
06-08-11 조회 4,171
06-08-08 조회 2,962
06-08-06 조회 3,318
06-08-05 조회 2,755
06-08-04 조회 3,233
06-08-04 조회 4,199
06-08-03 조회 3,408
06-07-25 조회 3,521
06-07-23 조회 3,286
06-07-22 조회 4,332
06-07-21 조회 2,979
06-07-21 조회 3,191
06-07-21 조회 3,151
06-07-20 조회 4,483
06-07-20 조회 5,270
06-07-20 조회 3,834
06-07-19 조회 4,294
06-07-19 조회 3,213
06-07-19 조회 4,869
06-07-19 조회 4,256
06-07-19 조회 3,377
06-07-12 조회 3,909
06-07-11 조회 5,541
06-07-11 조회 4,204
06-07-11 조회 2,736
06-07-11 조회 4,394
06-07-11 조회 3,513
06-07-11 조회 3,754
06-07-11 조회 2,892
06-07-11 조회 2,790
06-07-11 조회 3,483
06-06-27 조회 4,551
06-06-21 조회 4,230
06-06-15 조회 3,908
06-06-10 조회 3,346
06-06-05 조회 3,139
06-05-31 조회 4,221