0
이전에 MVC를 사용하여 이메일을 보내지 않았으며 조금 갇혀 있습니다.MVC를 사용하여 컨트롤러를 통해 이메일을 보내는 방법
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require '../vendor/autoload.php';
class Email {
public function sendMail()
{
$mail = new PHPMailer(true); // Passing `true` enables exceptions
try {
//Server settings
$mail->SMTPDebug = 2; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'mail.example.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = 'secret'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('[email protected]');
$mail->addAddress('[email protected]'); // Add a recipient // Name is optional
$mail->addReplyTo('[email protected]');
//Content
$mail->isHTML(true); // 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.';
echo 'Mailer Error: ' . $mail->ErrorInfo;
}
}
}
: 내 응용 프로그램 폴더에서
, 내가 Controller.php, Core.php, Database.php이있는 라이브러리 폴더가 내가 email.php로에서 email.php로
만들어 나는 클래스가
전자 메일보기에 액세스 할 때 전자 메일 보내기를 트리거하려고합니다. 그러나 나는 컨트롤러에 무엇을 넣을 지 모른다. 아래의 코드는 오류입니다.
public function email()
{
$this->sendMail();
$this->view('pages/email');
}
치명적인 오류 : catch되지 않은 오류 : 정의되지 않은 메서드 페이지에 전화 : 센드 메일()를
아, 그래 물론. 얼마나 어리석은 짓이야! – user8463989