Fla*_*nco 3 php smtp phpmailer fatal-error
我正在尝试使用 PHPMailer 通过 gmail SMTP 服务器发送邮件,但出现致命错误,并且找不到任何解决方案
\n我的 php 文件
\n<?php\nuse PHPMailer\\PHPMailer\\PHPMailer;\nuse PHPMailer\\PHPMailer\\Exception;\n\nrequire "phpmailer/PHPMailer.php";\nrequire "phpmailer/SMTP.php";\nrequire "phpmailer/Exception.php";\n\n$error_msg=null;\n$success_msg=null;\n\nif ($_POST) {\n //$name = isset($_POST['name']) ? filter_var($_POST['name'], FILTER_SANITIZE_STRING) : null;\n //$email = isset($_POST['email']) ? filter_var($_POST['email'], FILTER_VALIDATE_EMAIL) : null;\n //$message = htmlspecialchars($_POST['message']);\n\n $name = $_POST['name'];\n $email = $_POST['email'];\n $message = $_POST['message'];\n\n if (empty($name) || empty($email) || empty($message)) {\n $error_msg = 'Fill out required entry fields!';\n }\n\n if (is_null($error_msg)) {\n\n $mail = new PHPMailer(TRUE);\n\n $mail->isSMTP();\n $mail->Host = "smtp.gmail.com";\n $mail->SMTPAuth = true;\n $mail->Username = "mail@gmail.com";\n $mail->Password = "";\n $mail->SMTPSecure = "tls";\n $mail->Port = 587;\n\n $mail->isHTML(true);\n $mail->setFrom($email, $name);\n $mail->addAddress("mail@gmail.com");\n $mail->Subject = "Nowa wiadomo\xc5\x9b\xc4\x87 z formularza kontaktowego";\n $mail->Body = $message;\n\n $mail->send();\n\n $success_msg = "Message sent.";\n }\n}\n?>\nRun Code Online (Sandbox Code Playgroud)\nhtml表格
\n<div class="h-100 d-flex justify-content-center align-items-center">\n <div class="row">\n <div class="col-md-12 rounded">\n <?php echo $lang['contact_desc']?>\n\n <?php if ($error_msg) : ?>\n <div class="alert alert-danger"><?php echo $error_msg; ?></div>\n <?php endif; ?>\n\n <?php if ($success_msg) : ?>\n <div class="alert alert-success"><?php echo $success_msg; ?></div>\n <?php endif; ?>\n <form id="myform" method="post">\n <label for="name"><?php echo $lang['name']?></label>\n <input type="text" name="name" id="name" placeholder="<?php echo $lang['name']?>" required>\n\n <label for="email">Email</label>\n <input type="email" name="email" id="email" placeholder="example@example.com" required>\n\n <label for="message"><?php echo $lang['message']?></label>\n <textarea name="message" id="message" placeholder="<?php echo $lang['msg_content']?>" required></textarea>\n\n <input type="submit" name="submit" value="<?php echo $lang['submit']?>">\n </form>\n </div>\n </div>\n</div>\nRun Code Online (Sandbox Code Playgroud)\n我得到的错误:
\n致命错误:未捕获错误:未定义常量 PHPMailer\\PHPMailer\\FILTER_FLAG_HOST_REQUIRED" in C:\\xampp\\htdocs\\phpmailer\\PHPMailer.php:3598 堆栈跟踪:#0 C:\\xampp\\htdocs\\ phpmailer\\PHPMailer.php(3564): PHPMailer\\PHPMailer\\PHPMailer::isValidHost('localhost') #1 C:\\xampp\\htdocs\\phpmailer\\PHPMailer.php(2304): PHPMailer\\ PHPMailer\\PHPMailer->serverHostname() #2 C:\\xampp\\htdocs\\phpmailer\\PHPMailer.php(1421): PHPMailer\\PHPMailer\\PHPMailer->createHeader() #3 C:\\xampp \\htdocs\\phpmailer\\PHPMailer.php(1316): PHPMailer\\PHPMailer\\PHPMailer->preSend() #4 C:\\xampp\\htdocs\\scripts\\form.php(43): PHPMailer \\PHPMailer\\PHPMailer->send() #5 C:\\xampp\\htdocs\\contact.php(3): include('C:\\xampp\\htdocs...') #6 {main } 抛出在 C:\\xampp\\htdocs\\phpmailer\\PHPMailer.php 第 3598 行
\n有任何想法吗?
\n