Sah*_*mal 1 php email phpmailer
我正在做一个项目,我需要在用户输入电子邮件和密码后发送电子邮件.他们可以激活他们发送电子邮件的帐户点击.但是当我使用PHPMailer时我得到了错误.错误是这样的
致命错误:未捕获错误:在C:\ xampp\htdocs\E-Commerce-New-2\registration.php中找不到类'PHPMailer\PHPMailer':20堆栈跟踪:#0 {main}抛出C:\ xampp \第20行的htdocs\E-Commerce-New-2\registration.php
在新的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";
}
}
?>
Run Code Online (Sandbox Code Playgroud)
任何人都可以给我一个建议吗?
在新的PHPMailer v6.0 +中,您现在需要将PHPMailer类导入到PHP脚本最顶层的全局命名空间中.
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
require 'path/to/PHPMailer/src/Exception.php';
require 'path/to/PHPMailer/src/PHPMailer.php';
require 'path/to/PHPMailer/src/SMTP.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "mail.example.com";
$mail->SetFrom("$from", "$from");
$mail->AddAddress("$to");
$mail->Subject = "$subject";
$mail->Body = "$message";
$mail->Send();
Run Code Online (Sandbox Code Playgroud)