필요한 파일
/lib/class.phpmailer.php
/lib/class.smtp.php
/lib/PHPMailerAutoload.php
require '/lib/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPSecure = 'tls';
$mail->CharSet = "utf-8";
$mail->Encoding = "base64";
$mail->isSMTP();
//Enable SMTP debugging
// 0 = off (for production use)
// 1 = client messages
// 2 = client and server messages
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = '메일서버주소';
$mail->Port = '포트';
$mail->SMTPAuth = false;//true 또는 false
$mail->Username = '유저명';
$mail->Password = '비밀번호';
$mail->setFrom('발신자이메일', '발신자명');//보내는이
$mail->addAddress('수신자이메일1', '수신자명1');//받는이
$mail->addAddress('수신자이메일2', '수신자명2');//받는이
(계속 추가할 수 있음)
$mail->addCC('cc메일주소', 'cc수신자명');
$mail->addBCC('bcc메일주소', 'bcc수신자명');
$mail->addReplyTo('답변받을이메일', '답변받는자');//답변받는자
$subject = "메일제목입니다.";
//$subject = "=?utf-8?B?".base64_encode($subject)."?=\n";//UTF-8이 아닌 경우
$mail->Subject = $subject;
$body = "메일본문. html 가능";
$body = file_get_contents('/where/message.html');//html파일을 가져올 경우
$mail->msgHTML($body, dirname(__FILE__));
$mail->AltBody = '이메일 본문입니다.';
//폼으로 넘어온 첨부파일(userfile)이 있는 경우
if (array_key_exists('userfile', $_FILES)) {
$uploadfile = tempnam(sys_get_temp_dir(), sha1($_FILES['userfile']['name']));
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
$mail->addAttachment($uploadfile, 'My uploaded file');
}
}
//send the message, check for errors
if (!$mail->send()) {
echo $mail->ErrorInfo;//에러메시지 출력
} else {
echo "전송성공!";
}
'PHP' 카테고리의 다른 글
magento23.0 OSX 모하비에 설치 (0) | 2019.03.03 |
---|---|
zendframework 3 설치 (0) | 2019.02.28 |
코드이그나이터 3.1.9 + 오라클 데이터베이스 세션 (0) | 2019.01.08 |
PHP7 session_regenerate_id() 대체 (0) | 2019.01.08 |
IIS PHP 헤더설정 (0) | 2019.01.08 |