<?php//Import PHPMailer classes into the global namespace//These must be at the top of your script, not inside a functionusePHPMailer\PHPMailer\PHPMailer;
usePHPMailer\PHPMailer\SMTP;
usePHPMailer\PHPMailer\Exception;
//Load Composer's autoloaderrequire'vendor/autoload.php';
//Create an instance; passing `true` enables exceptions$mail = new PHPMailer(true);
try {
//Server settings$mail->SMTPDebug = SMTP::DEBUG_SERVER; // SMTP 디버깅 유무(Enable verbose debug output)$mail->isSMTP(); //SMTP 사용 (Send using SMTP)$mail->Host = 'smtp.example.com'; // SMTP 서버 주소(Set the SMTP server to send through)$mail->SMTPAuth = true; // SMTP 인증 유무(Enable SMTP authentication)$mail->Username = 'user@example.com'; // SMTP 계정(SMTP username)$mail->Password = 'secret'; // SMTP 비밀번호(SMTP password)$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; // SMTP 암호화 (Enable implicit SSL encryption)$mail->Port = 465; // SMTP 포트(TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`)//Recipients$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User'); // 수신자 이메일, 이름 (Add a recipient)$mail->addAddress('ellen@example.com'); // 수신자 이메일 (Name is optional)$mail->addReplyTo('info@example.com', 'Information'); // ReplyTo(응답) 이메일, 이름$mail->addCC('cc@example.com'); // 참조 $mail->addBCC('bcc@example.com'); // 숨은 참조//Attachments$mail->addAttachment('/var/tmp/file.tar.gz'); // 첨부파일(Add attachments)$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name//Content$mail->isHTML(true); // 이메일 포맷 (HTML) (Set email format to HTML)$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo'Message has been sent';
}
catch (Exception$e)
{
echo"Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
?>
<?php/*
* 디버깅 옵션(debug options)
* DEBUG_OFF (`0`) No debug output, default
* DEBUG_CLIENT (`1`) Client commands
* DEBUG_SERVER (`2`) Client commands and server responses
* DEBUG_CONNECTION (`3`) As DEBUG_SERVER plus connection status
* DEBUG_LOWLEVEL (`4`) Low-level data output, all messages.
*/$mail->SMTPDebug = SMTP::DEBUG_SERVER;
/*
* 암호화 (encryption)
* ENCRYPTION_STARTTLS = 'tls';
* ENCRYPTION_SMTPS = 'ssl';
*
*/$mail->SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS; (Enable implicit TLS encryption)
$mail->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; (Enable implicit SSL encryption)
?>
<?php$mail->isSMTP();
// SMTP 서버 연결 정보 (SMTP Server connection informations)$mail->Host = 'smtp.example.com';
$mail->Username = 'user@example.com';
$mail->Password = 'secret';
$mail->Port = 465;
// 이메일 송수신 정보 (mail client informations)$mail->setFrom('from@example.com', 'Mailer');
$mail->addAddress('joe@example.net', 'Joe User');
// 이메일 내용 (mail contents)$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
// 이메일 전송 (send mail)$mail->send();
?>
댓글