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,187건
+
제목 글쓴이 날짜 조회
06-08-18 조회 2,935
06-08-18 조회 3,036
06-08-14 조회 2,472
06-08-13 조회 2,765
06-08-12 조회 3,902
06-08-12 조회 3,032
06-08-11 조회 4,250
06-08-11 조회 4,199
06-08-10 조회 3,295
06-08-10 조회 2,873
06-08-09 조회 3,920
06-08-08 조회 3,928
06-08-08 조회 5,180
06-08-08 조회 3,047
06-08-07 조회 3,784
06-08-06 조회 3,416
06-08-06 조회 4,543
06-08-05 조회 2,495
06-08-05 조회 2,563
06-08-05 조회 2,851
06-08-05 조회 3,325
06-08-05 조회 2,877
06-08-05 조회 2,805
06-08-04 조회 3,187
06-08-04 조회 3,326
06-08-04 조회 6,024
06-08-04 조회 3,424
06-08-04 조회 4,281
06-08-04 조회 3,723
06-08-03 조회 3,508
06-08-01 조회 5,776
06-07-31 조회 3,626
06-07-31 조회 3,459
06-07-30 조회 3,004
06-07-30 조회 2,784
06-07-29 조회 4,473
06-07-29 조회 3,427
06-07-28 조회 7,252
06-07-27 조회 3,184
06-07-26 조회 2,935
06-07-26 조회 3,807
06-07-26 조회 2,856
06-07-26 조회 3,347
06-07-25 조회 3,222
06-07-25 조회 4,651
06-07-25 조회 3,612
06-07-25 조회 3,818
06-07-24 조회 5,476
06-07-24 조회 4,716
06-07-23 조회 3,411
06-07-23 조회 5,496
06-07-22 조회 4,445
06-07-21 조회 5,262
06-07-21 조회 3,095
06-07-21 조회 3,290
06-07-21 조회 3,253
06-07-20 조회 4,406
06-07-20 조회 3,814
06-07-20 조회 4,567
06-07-20 조회 3,784
06-07-20 조회 3,615
06-07-20 조회 3,472
06-07-20 조회 3,307
06-07-20 조회 3,235
06-07-20 조회 5,374
06-07-20 조회 3,773
06-07-20 조회 3,297
06-07-20 조회 3,336
06-07-20 조회 3,968
06-07-19 조회 3,047
06-07-19 조회 4,384
06-07-19 조회 3,927
06-07-19 조회 3,387
06-07-19 조회 2,880
06-07-19 조회 3,308
06-07-19 조회 3,159
06-07-19 조회 3,000
06-07-19 조회 3,553
06-07-19 조회 3,400
06-07-19 조회 4,979
06-07-19 조회 4,842
06-07-19 조회 3,356
06-07-19 조회 4,383
06-07-19 조회 3,082
06-07-19 조회 3,512
06-07-19 조회 3,430
06-07-17 조회 3,435
06-07-17 조회 3,271
06-07-16 조회 3,865
06-07-14 조회 3,916
06-07-14 조회 4,319
06-07-14 조회 4,192
06-07-14 조회 3,798
06-07-13 조회 4,085
06-07-13 조회 4,265
06-07-12 조회 4,011
06-07-11 조회 3,715
06-07-11 조회 4,001
06-07-11 조회 5,640
06-07-11 조회 3,550