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>
|
댓글을 작성하시려면 로그인이 필요합니다.

프로그램

8,188건
+
제목 글쓴이 날짜 조회
06-08-18 조회 3,209
06-08-18 조회 2,874
06-08-18 조회 2,985
06-08-14 조회 2,426
06-08-13 조회 2,704
06-08-12 조회 3,851
06-08-12 조회 2,969
06-08-11 조회 4,194
06-08-11 조회 4,144
06-08-10 조회 3,247
06-08-10 조회 2,822
06-08-09 조회 3,878
06-08-08 조회 3,883
06-08-08 조회 5,131
06-08-08 조회 2,988
06-08-07 조회 3,727
06-08-06 조회 3,357
06-08-06 조회 4,490
06-08-05 조회 2,438
06-08-05 조회 2,517
06-08-05 조회 2,799
06-08-05 조회 3,273
06-08-05 조회 2,829
06-08-05 조회 2,768
06-08-04 조회 3,131
06-08-04 조회 3,268
06-08-04 조회 5,969
06-08-04 조회 3,374
06-08-04 조회 4,226
06-08-04 조회 3,672
06-08-03 조회 3,453
06-08-01 조회 5,722
06-07-31 조회 3,576
06-07-31 조회 3,412
06-07-30 조회 2,953
06-07-30 조회 2,745
06-07-29 조회 4,435
06-07-29 조회 3,388
06-07-28 조회 7,203
06-07-27 조회 3,142
06-07-26 조회 2,899
06-07-26 조회 3,767
06-07-26 조회 2,816
06-07-26 조회 3,294
06-07-25 조회 3,176
06-07-25 조회 4,592
06-07-25 조회 3,553
06-07-25 조회 3,765
06-07-24 조회 5,424
06-07-24 조회 4,656
06-07-23 조회 3,342
06-07-23 조회 5,443
06-07-22 조회 4,387
06-07-21 조회 5,199
06-07-21 조회 3,022
06-07-21 조회 3,232
06-07-21 조회 3,194
06-07-20 조회 4,350
06-07-20 조회 3,748
06-07-20 조회 4,508
06-07-20 조회 3,740
06-07-20 조회 3,568
06-07-20 조회 3,435
06-07-20 조회 3,276
06-07-20 조회 3,196
06-07-20 조회 5,318
06-07-20 조회 3,712
06-07-20 조회 3,255
06-07-20 조회 3,283
06-07-20 조회 3,881
06-07-19 조회 2,986
06-07-19 조회 4,324
06-07-19 조회 3,868
06-07-19 조회 3,339
06-07-19 조회 2,842
06-07-19 조회 3,251
06-07-19 조회 3,086
06-07-19 조회 2,939
06-07-19 조회 3,503
06-07-19 조회 3,339
06-07-19 조회 4,910
06-07-19 조회 4,780
06-07-19 조회 3,296
06-07-19 조회 4,301
06-07-19 조회 3,006
06-07-19 조회 3,432
06-07-19 조회 3,361
06-07-17 조회 3,375
06-07-17 조회 3,206
06-07-16 조회 3,807
06-07-14 조회 3,859
06-07-14 조회 4,256
06-07-14 조회 4,121
06-07-14 조회 3,724
06-07-13 조회 4,012
06-07-13 조회 4,200
06-07-12 조회 3,942
06-07-11 조회 3,648
06-07-11 조회 3,946
06-07-11 조회 5,571