반응형
보통 메일을 보낼 때 php안에 있는 mail 함수가 있는데
이를 사용하면 메일을 성공적으로 전송하는데 걸리는 시간이 오래 걸리며,
에러가 어디서 났는지 확인하기가 힘든 단점이 있다.
그래서 좀 더 효율적인 메일 라이브러리가 있는데
이 라이브러리는 phpmailer이다.
소스를 다운 받는 곳은
http://phpmailer.worxware.com/ 이며
downloads를 눌러서 php 버젼에 맞는 것을 download하면 된다.
(http://phpmailer.worxware.com/index.php?pg=sf&p=sfp)
깃허브 : https://github.com/Synchro/PHPMailer
IsSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp1.example.com;smtp2.example.com'; // smtp 주소 $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'jswan'; // SMTP username 메일주소 $mail->Password = 'secret'; // SMTP password 메일 접속 시 비밀번호 $mail->SMTPSecure = 'tls'; // Enable encryption, 'ssl' also accepted $mail->From = 'from@example.com'; //보내는 사람 메일 주소 $mail->FromName = 'Mailer'; //보내는 사람 이름 $mail->AddAddress('josh@example.net', 'Josh Adams'); // Add a recipient 받는 사람 주소, 받는 사람 이름 $mail->AddAddress('ellen@example.com'); // Name is optional 받는 사람 이메일 주소만 $mail->AddReplyTo('info@example.com', 'Information'); $mail->AddCC('cc@example.com'); // 참조 $mail->AddBCC('bcc@example.com'); //숨은 참조 $mail->WordWrap = 50; // Set word wrap to 50 characters $mail->AddAttachment('/var/tmp/file.tar.gz'); // Add attachments 첨부 파일이 있을 경우 $mail->AddAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 첨부 파일과 첨부파일 명 $mail->IsHTML(true); // Set email format to HTML 메일을 보낼 때 html 형식으로 메일을 보낼 경우 true $mail->Subject = 'Here is the subject'; //메일 주소 $mail->Body = 'This is the HTML message body in bold!'; //메일 본문 $mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; // 메일 본문을 오로지 텍스트 형식으로만 보낼 때 if(!$mail->Send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; // 메일 전송에 실패 했을 경우 뜨는 에러 메세지 exit; } echo 'Message has been sent';한글이 깨지는 경우가 생기는데 iconv("utf-8","euc-kr","한글텍스트")로 해결해준다.
반응형
'Old > PHP' 카테고리의 다른 글
쌍따옴표 제거, 백슬레시제거 (0) | 2013.08.02 |
---|---|
자동 로그인 소스 (0) | 2013.08.01 |
php 익스플로어 버젼 체크 (0) | 2013.08.01 |
글자수 줄이기 mb_strimwidth (0) | 2013.07.17 |
facebook comment plugin json parsing (0) | 2013.07.12 |