【发布时间】:2017-11-25 13:11:23
【问题描述】:
我正在做一个项目,我需要在用户输入电子邮件和密码后发送电子邮件。他们可以激活他们的帐户点击发送电子邮件。但是当我使用 PHPMailer 时出现错误。错误是这样的
致命错误:未捕获的错误:未找到类 'PHPMailer\PHPMailer' C:\xampp\htdocs\E-Commerce-New-2\registration.php:20 堆栈跟踪:#0 {main} 在 C:\xampp\htdocs\E-Commerce-New-2\registration.php 中抛出 第 20 行
在新的 PHPMailer 版本中使用 PHPMailerAutoload.php 文件?我认为答案是否定的。
我尝试使用该代码$mail = new PHPMailer\PHPMailer(); 以及此代码$mail = new PHPMailer(); 尚未有人使用。我把我的文件结构放在下面
在这里,我已经超越了我的代码行。
<?php
session_start();
include("includes/db.php");
include("functions/functions.php");
include('PHPMailer/PHPMailer.php');
?>
<?php
// If the values are posted, insert them into the database.
if (isset($_POST['email']) && isset($_POST['password'])){
$email = $_POST['email'];
$password = $_POST['password'];
$verification_key = md5($email);
$query = "INSERT INTO `customers` (customer_pass,customer_email,verification_key) VALUES ('$password', '$email','$verification_key')";
$result = mysqli_query($con, $query);
if($result){
$mail = new PHPMailer\PHPMailer();
$mail->setFrom('noreplay@clickshop.com');
$mail->addAddress($email,'test');
$mail->Subject = "Verify Your Account";
$mail->isHTML(true);
$mail->Body = ' Please verify your email address to activate your account by clicking on this link <br>
<a href="http://localhost/E-Commerce-New-2/verify.php?key="'. $verification_key.'>Click Here</a>';
if(!$mail->send()) {
$fmsg= 'Message could not be sent. Mailer Error: ' . $mail->ErrorInfo;
} else {
$smsg = 'User Registration successfull. Please Check your email to Activate Account!';
}
}else{
$fmsg = "User registration failed";
}
}
?>
谁能给我一个建议?
【问题讨论】:
-
有些人在没有任何理由的情况下否决了这个问题
-
你真的需要付出最小的努力来解决这个问题——这可能就是你投票失败的原因。阅读 PHPMailer 附带的自述文件,并根据提供的示例编写代码。
-
花3个小时的功夫可能不多吧?我知道了。谢谢你的建议