Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
未使用phpMailer收到任何电子邮件_Php_Phpmailer - Fatal编程技术网

未使用phpMailer收到任何电子邮件

未使用phpMailer收到任何电子邮件,php,phpmailer,Php,Phpmailer,我没有收到任何电子邮件,请查看我的代码并更正“phpMailer部分”中的错误。如果我无法设置此项,则无法设置smtp PHPmailer文件夹位于另一个目录中,与includes/initialize目录完全连接 <?php require_once("../includes/initialize.php"); ?> <?php if ($session->is_logged_in()) { redirect_to('loggedin.php'); }?> <

我没有收到任何电子邮件,请查看我的代码并更正“phpMailer部分”中的错误。如果我无法设置此项,则无法设置smtp

PHPmailer文件夹位于另一个目录中,与includes/initialize目录完全连接

<?php require_once("../includes/initialize.php"); ?>
<?php if ($session->is_logged_in()) { redirect_to('loggedin.php'); }?>
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\Exception;
use PHPMailer\PHPMailer\SMTP;
?>
<?php $timestamp = strftime("%Y-%m-%d %H:%M:%S", time()); ?>
<?php
if(isset($_POST['submit'])) { 
    $first_name     =    $_POST['first_name'];
    $last_name      =    $_POST['last_name'];
    $mobile         =    $_POST['mobile_number'];
    $email          =    $_POST['email_address'];
    $username       =    $_POST['username'];
    $password       =    $_POST['password'];
    $cpassword      =    $_POST['confirm_password'];

    $token = 'vfjhvbkebecbjDRCWVJEcbkrvlnke24t@r7c_!+#%vbejw(968';
    $token = str_shuffle($token);
    $token = substr($token, 0, 10);
    //some contents removed     

    $customer = new Customer_reg();
    $customer->first_name       = $first_name;
    $customer->last_name        = $last_name;
    $customer->email_address    = $email;
    $customer->username         = $username;
    $customer->password         = $password;
    $customer->mobile_number    = $mobile;
    $customer->emailConfirm     = 0;
    $customer->created_at       = $timestamp;
    $customer->updated_at       = $timestamp;
    $customer->token            = $token;
    if($customer->save()) {

    $from       = "whatever@mail.com";
    $fromName   = "something";
    $addAddress = "user@mail.com"; 
    $subject    = "Email Confirmation ".strftime("%Y", time());
    //send email
    $mail =  new PHPMailer();
    $mail->setFrom     = $from;
    $mail->addAddress($addAddress);
    $mail->Subject  = $subject;
    $mail->isHTML  (true);
    $mail->Body     = "Please click the link to verify your email
    <br><br>
    <a href='http://www.mywebsite/phpEmailConfirmation/confirm.php?email=$email&token=$token>click here</a>
    ";
//code not sending any emails
    $mail->Send();
    $session->message('<div class="btn bg-success">Account created sucessfully please verify your email.</div>');
        redirect_to('login.php');
    } else {
        //failure

    }
    }
?>


您已将变量分配给
setFrom
methods name,而不是调用函数本身。您应该已激活错误消息以捕获此消息

$mail->setFrom($from, $fromName);
$mail->addAddress($addAddress);
$mail->Subject  = $subject;
$mail->isHTML(true);
$mail->Body     = "Please click the link to verify your email ...";

$mail->setFrom
听起来像是一个方法。@kerbholz它确实是一个method@CidThx,我知道,我读过;)您在这段代码中根本没有错误检查或报告,所以您无法判断发生了什么问题。以PHPMailer提供的示例为基础编写代码,至少您会看到哪里出了问题。