Не получил никаких писем с использованием phpMailer - PullRequest
0 голосов
/ 04 октября 2018

Я не получаю никаких писем, пожалуйста, посмотрите на мой код и исправьте мои ошибки в "разделах phpMailer".Если я не могу установить это, то я не могу настроить smtp.

Папка PHPmailer находится в другом каталоге и прекрасно подключена из каталога include / 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 голосов
/ 04 октября 2018

Вы назначили переменные для setFrom имени метода вместо вызова самой функции.Вы должны были активировать сообщения об ошибках, чтобы поймать это.

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