php에서 SMTP 서버를 이용한 메일 보내기

by kay posted May 06, 2013
?

단축키

Prev이전 문서

Next다음 문서

ESC닫기

크게 작게 위로 아래로 댓글로 가기 인쇄

원문 Url : http://www.phpgenious.com/2010/04/send-php-mail-using-smtp/#more-390

downLoad : PHPMailer_v5.1.zip


- Auth 유무 및 HTML 유무 셋팅


실제 메일 발송시 쓰는 Class 파일은 

class.phpmailer.php , class.smtp.php

위 2개의 파일입니다.


<?php

include("class.phpmailer.php");

$mail = new PHPMailer();
$mail->ContentType = "text/html"; 
$mail->CharSet = "utf-8"; // 한글/한자 깨짐 방지

$mail->IsSMTP(); // set mailer to use SMTP

$mail->Host = "host"; // specify main and backup server

$mail->SMTPAuth = true; // turn on SMTP authentication

$mail->Username = "id"; // SMTP username

$mail->Password ="password"; // SMTP password

$mail->From = "from mail"; //do NOT fake header.

$mail->FromName = "from name";

$mail->AddAddress("to mail"); // Email on which you want to send mail

$mail->AddReplyTo("reply mail", "rely name"); //optional

$mail->IsHTML(true);

$mail->Subject = "subject";

$mail->Body = "test mail";
 
if(!$mail->Send())

{ 
	echo $mail->ErrorInfo;

}else{
	echo "email was sent";
} 
?>