【发布时间】:2018-08-24 02:23:44
【问题描述】:
在数据库中保存数据后发送确认邮件。我用过PHPMailer。
我的代码
<?php include_once 'config/init.php'; ?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
$user = new user();
if(isset($_POST['submitsignup'])){
$date = array();
if($_POST['email']=='' || $_POST['password']=='' || $_POST['first_name']=='' || $_POST['last_name']==''){
echo "Fill all the stuff";
}
else{
$result=$user->checkemails($_POST['email']);
if(!$result){
$data["email"] = $_POST['email'];
$data['password'] = $_POST['password'];
$data['first_name'] =$_POST['first_name'];
$data['last_name'] = $_POST['last_name'];
$token = 'qwertyuiopasdfghjklzxcvbnm!$#()/1234567890';
$token = str_shuffle($token);
$token = substr($token,0,10);
$user->signup($data,$token);
include_once "PHPMailer/PHPMailer.php";
$mail = new PHPMailer();
$mail->setFrom("ahsan44411@gmail.com");
$mail->addAddress($data["email"],$data["first_name"]);
$mail->Subject = "Please verify name";
$mail->isHTML(true);
$mail->Body = "Please click on the Link below <br><br>
<a href='localhost/index.php'></a>";
if($mail->send()){
echo "Message sent";
}else{
echo "Something went wrong";
}
}
else{
echo "Email aleay present";
}
}
}
$template = new Template('templates/signuptemp.php');
但是我遇到了这样的错误
警告:require_once(lib/PHPMailer\PHPMailer\Exception.php):无法打开流:第 10 行的 C:\wamp64\www\jobLister\config\init.php 中没有这样的文件或目录
致命错误:require_once():在 C:\wamp64\www\jobLister 中打开所需的 'lib/PHPMailer\PHPMailer\Exception.php' (include_path='.;C:\php\pear') 失败\config\init.php 第 10 行
我的配置\init.php
<?php
require_once 'config.php';
//Autoloader
function __autoload($class_name){
require_once 'lib/'.$class_name.'.php';
}
?>
我无法真正理解这个问题,如果您能解释发生这种情况的原因,我将不胜感激。干杯
编辑:它不起作用,因为我已经在使用自动加载器来加载我的文件,在这种情况下我不应该使用 include_once 函数
【问题讨论】:
-
你为什么要写你自己的自动加载器?基本上它需要更聪明,并将完全限定的类名拆分为对应于目录。但实际上,为什么不直接使用 composer?
-
我正在使用自动加载器,因此我不必为 lib 中的每个文件都使用 require_once。
-
你收到了吗。问题?出了什么问题
-
您可以在
require_once之前echo $class_name;获取在文件中找不到的类名。 -
对不起,我不知道这对我有什么帮助
标签: php