这是我在php中的代码:
<?php
if (isset($_POST['richiediOTP'])) {
$utente_visualizzante = $userRow['userEmail'];
try {
require 'config/phpmailer/vendor/autoload.php';
$mail = new PHPMailer(true);
//Server settings
require 'config/phpmailer/config-mail.php';
//Recipients
$mail->addAddress('HIDDEN MAIL', 'HIDDEN NAME');
// Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>
当我单击表单中的按钮时,它甚至没有告诉我电子邮件已发送,“要求'config / phpmailer / vendor / autoload.php';”而是配置“需要'config / phpmailer / config-mail.php';”这也在那里,并具有数据,例如“ smtp debug 2”。我不知道该怎么解决...
这是<form action="" method="post">
中包含的按钮:
<button name="submitChange" style="border-radius:0px" type="submit" class="button">Rimuovi Portafoglio</button>
啊,在配置邮件中还有一个字符串:“ $ mail-> setFrom('MAIL HIDDEN','HIDDEN');”
答案 0 :(得分:-1)
只需将require语句从try and catch块中移出(尽管没关系),然后使用使用PHPMailer
类所需的类。有关更多信息,请参见Github phpmailer page,也将类实例也放在块外。
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'config/phpmailer/vendor/autoload.php';
//Server settings
require 'config/phpmailer/config-mail.php';
if (isset($_POST['richiediOTP'])) {
$utente_visualizzante = $userRow['userEmail'];
$mail = new PHPMailer(true);
try {
//Recipients
$mail->addAddress('HIDDEN MAIL', 'HIDDEN NAME');
// Content
$mail->isHTML(true);
$mail->Subject = 'Here is the subject';
$mail->Body = 'This is the HTML message body <b>in bold!</b>';
$mail->send();
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
}
?>