没有使用phpMailer收到任何电子邮件

时间:2018-10-04 10:41:47

标签: php phpmailer

我没有收到任何电子邮件,请查看我的代码并在“ 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

    }
    }
?>

我认为不需要发布html表单...

1 个答案:

答案 0 :(得分:1)

您已将变量分配给setFrom方法名称,而不是调用函数本身。您应该已激活错误消息来捕获此错误。

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