简体   繁体   中英

PHPMailer not working in my cPanel

Here is my code for PHPMailer:

<?php
    error_reporting(E_ALL);
    require '/home/user/public_html/phpmailer/PHPMailerAutoload.php';
    $mail = new PHPMailer;
    $mail->isSMPT();
    $mail->Host = 'smpt.gmail.com'; // Specify main and backup SMTP servers
    $mail->SMTPAuth = true; // Enable SMTP authentication
    $mail->Username = '*****@gmail.com'; // SMTP username
    $mail->Password = 'password'; // SMTP password
    $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 587; // TCP port to connect to 587
    $mail->SMPTDebug = 4;
    $mail->setFrom('******@gmail.com', 'Hello whats happening');
    $mail->addAddress('****@gmail.com'); // Add a recipient
    // $mail->addAddress('ellen@example.com'); // Name is optional
    $mail->addReplyTo('itskosieric@gmail.com');
    //$mail->addCC('cc@example.com');
    //$mail->addBCC('bcc@example.com');

    //$mail->addAttachment('/var/tmp/file.tar.gz'); // Add attachments
    //$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
    $mail->isHTML(true); // Set email format to HTML

    $mail->Subject = 'hi just wanted to say hello';
    $mail->Body = '<p>This is the HTML message body <b>in bold!</b></p>';
    $mail->AltBody = 'This is the body in plain text for non-HTML mail clients';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
?>

It only says "message has been sent" when I comment $mail->isSMPT(); but doesn't send any E-mail. Please I don't know where this problem is coming from.

SMTP, not SMPT. Apart from that, base your code on examples provided with PHPMailer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM