PHPMailer无法在我的cPanel

时间:2017-06-08 22:56:06

标签: php phpmailer

这是我的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';
    }
?>

当我发表评论$mail->isSMPT();但没有发送任何电子邮件时,它只会说“已发送消息”。我不知道这个问题来自哪里。

1 个答案:

答案 0 :(得分:1)

SMTP,而不是SMPT。除此之外,将代码基于PHPMailer提供的示例。