0
MVCを使用して電子メールを送信していないので、ちょっとしたことがあります。私のアプリフォルダでMVCを使用してコントローラ経由で電子メールを送信する方法
、私はController.phpを持っているライブラリフォルダを持っている、core.phpの、database.phpでと私はクラスを持っているEmail.phpでEmail.php
を作成しました:
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;
}
}
}
私は電子メールビューにアクセスすると、電子メールの送信をトリガーしようとしています。しかし、私はコントローラーに何を入れるべきか分からない。以下のコードはエラーです。
public function email()
{
$this->sendMail();
$this->view('pages/email');
}
致命的なエラー:不明なエラー:未定義のメソッドのページへの呼び出し:: SENDMAIL()
ああ、はいもちろんのは。私の愚かなこと! – user8463989