D

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

· 2006-07-22 (토) 01:21:39 · 4344
출처: 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-08-18 조회 3,180
06-08-18 조회 2,843
06-08-18 조회 2,954
06-08-14 조회 2,397
06-08-13 조회 2,679
06-08-12 조회 3,809
06-08-12 조회 2,931
06-08-11 조회 4,177
06-08-11 조회 4,115
06-08-10 조회 3,210
06-08-10 조회 2,796
06-08-09 조회 3,853
06-08-08 조회 3,870
06-08-08 조회 5,113
06-08-08 조회 2,970
06-08-07 조회 3,689
06-08-06 조회 3,328
06-08-06 조회 4,470
06-08-05 조회 2,409
06-08-05 조회 2,479
06-08-05 조회 2,759
06-08-05 조회 3,245
06-08-05 조회 2,804
06-08-05 조회 2,743
06-08-04 조회 3,093
06-08-04 조회 3,237
06-08-04 조회 5,950
06-08-04 조회 3,351
06-08-04 조회 4,203
06-08-04 조회 3,639
06-08-03 조회 3,416
06-08-01 조회 5,699
06-07-31 조회 3,559
06-07-31 조회 3,391
06-07-30 조회 2,930
06-07-30 조회 2,722
06-07-29 조회 4,400
06-07-29 조회 3,350
06-07-28 조회 7,172
06-07-27 조회 3,116
06-07-26 조회 2,865
06-07-26 조회 3,741
06-07-26 조회 2,791
06-07-26 조회 3,261
06-07-25 조회 3,150
06-07-25 조회 4,558
06-07-25 조회 3,527
06-07-25 조회 3,741
06-07-24 조회 5,397
06-07-24 조회 4,633
06-07-23 조회 3,300
06-07-23 조회 5,412
06-07-22 조회 4,345
06-07-21 조회 5,173
06-07-21 조회 2,989
06-07-21 조회 3,199
06-07-21 조회 3,156
06-07-20 조회 4,328
06-07-20 조회 3,713
06-07-20 조회 4,490
06-07-20 조회 3,718
06-07-20 조회 3,537
06-07-20 조회 3,408
06-07-20 조회 3,252
06-07-20 조회 3,164
06-07-20 조회 5,283
06-07-20 조회 3,679
06-07-20 조회 3,225
06-07-20 조회 3,255
06-07-20 조회 3,842
06-07-19 조회 2,966
06-07-19 조회 4,303
06-07-19 조회 3,832
06-07-19 조회 3,307
06-07-19 조회 2,807
06-07-19 조회 3,219
06-07-19 조회 3,053
06-07-19 조회 2,893
06-07-19 조회 3,467
06-07-19 조회 3,300
06-07-19 조회 4,875
06-07-19 조회 4,742
06-07-19 조회 3,259
06-07-19 조회 4,265
06-07-19 조회 2,973
06-07-19 조회 3,395
06-07-19 조회 3,322
06-07-17 조회 3,346
06-07-17 조회 3,184
06-07-16 조회 3,791
06-07-14 조회 3,839
06-07-14 조회 4,223
06-07-14 조회 4,090
06-07-14 조회 3,687
06-07-13 조회 3,982
06-07-13 조회 4,165
06-07-12 조회 3,914
06-07-11 조회 3,626
06-07-11 조회 3,917
06-07-11 조회 5,546