D

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

· 2006-07-22 (토) 01:21:39 · 4360
출처: 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건
+
제목 글쓴이 날짜 조회
07-10-13 조회 5,128
07-10-03 조회 4,110
07-10-03 조회 3,303
07-10-03 조회 2,531
07-10-03 조회 4,626
07-10-02 조회 2,963
07-10-01 조회 3,590
07-09-28 조회 3,502
07-09-27 조회 4,566
07-08-16 조회 6,411
07-08-04 조회 2,860
07-07-25 조회 6,126
07-07-05 조회 4,009
07-07-02 조회 4,554
07-06-30 조회 4,457
07-06-20 조회 7,344
07-06-20 조회 3,957
07-06-05 조회 4,133
07-05-26 조회 3,164
07-05-17 조회 9,157
07-05-17 조회 5,198
07-05-04 조회 6,126
07-04-15 조회 6,213
07-04-13 조회 3,988
07-04-11 조회 3,394
07-03-20 조회 3,570
07-03-02 조회 6,793
07-02-27 조회 6,061
07-02-22 조회 4,455
07-01-30 조회 6,277
07-01-30 조회 1만
06-12-20 조회 3,777
06-12-18 조회 4,617
06-12-15 조회 4,588
06-12-15 조회 3,818
06-12-15 조회 3,205
06-11-30 조회 3,647
06-11-27 조회 4,547
06-10-24 조회 6,458
06-10-17 조회 4,765
06-09-22 조회 4,511
06-09-21 조회 6,009
06-09-21 조회 3,929
06-09-15 조회 6,550
06-08-20 조회 3,696
06-07-19 조회 3,335
06-07-14 조회 4,231
06-07-14 조회 4,099
06-07-11 조회 5,705
06-06-08 조회 4,285
06-06-08 조회 4,196
06-05-24 조회 3,512
06-05-24 조회 4,898
06-05-17 조회 3,612
06-05-16 조회 4,361
06-05-14 조회 6,055
06-05-12 조회 3,619
06-05-06 조회 4,258
06-05-06 조회 4,341
06-05-06 조회 3,647
06-05-06 조회 3,713
06-05-06 조회 4,161
06-04-25 조회 4,027
06-03-23 조회 5,487
06-01-20 조회 4,054
06-01-04 조회 4,267
05-12-30 조회 4,140
05-12-21 조회 4,817
05-11-09 조회 4,018
05-11-09 조회 3,805
05-10-09 조회 3,461
05-09-21 조회 6,848
05-08-14 조회 4,332
05-08-04 조회 5,513
05-07-14 조회 4,575
05-06-15 조회 4,966
05-04-23 조회 4,563
05-04-20 조회 5,017
05-04-19 조회 1.1만
05-04-19 조회 5,978
05-03-15 조회 3,802
05-03-15 조회 4,242
05-03-13 조회 2,924
05-03-13 조회 3,445
05-03-13 조회 3,429
05-03-13 조회 2,733
05-03-13 조회 5,777
05-03-13 조회 5,409
05-03-13 조회 4,342
05-03-13 조회 4,636
05-03-13 조회 7,894
05-03-13 조회 4,394
05-03-13 조회 3,479
05-03-13 조회 3,474
05-03-13 조회 8,020
05-03-13 조회 5,478
05-03-13 조회 4,127
05-03-12 조회 3,772
05-03-12 조회 4,478
05-02-24 조회 4,629