PHP输出的代码不是正确的输出

PHP输出的代码不是正确的输出,php,phpmailer,Php,Phpmailer,我是PHP新手。我一直在努力让这个邮件器工作,我已经让它的大部分工作。 以下是我的PHP: <?php require __DIR__ . '/vendor/autoload.php'; $included_files = get_included_files(); foreach ($included_files as $filename) { echo "$filename\n"; } $mail = new PHPMaile

我是PHP新手。我一直在努力让这个邮件器工作,我已经让它的大部分工作。 以下是我的PHP:

    <?php
    require __DIR__ . '/vendor/autoload.php';
    $included_files = get_included_files();

    foreach ($included_files as $filename) {
    echo "$filename\n";
    }

    $mail = new PHPMailer;

    $mail->isSMTP();                                      // Set mailer to use SMTP
    $mail->Host = 'smtp.gmail.com';  // Specify main and backup SMTP servers
    $mail->SMTPAuth = true;                               // Enable SMTP authentication
    $mail->Username = 'rottenrobbie911@gmail.com';                 // SMTP username
    $mail->Password = '';                           // SMTP password
    $mail->SMTPSecure = 'tls';                            // Enable TLS encryption, `ssl` also accepted
    $mail->Port = 465; 

    $mail->setFrom('from@example.com', 'Mailer');
    $mail->addAddress('yalnifcam2@gmail.com', 'Joe User');

    $mail->Subject = 'GenericSubject';
    $mail->Body    = 'This is the HTML message body <b>in bold!</b>';

    if(!$mail->send()) {
        echo 'Message could not be sent.';
        echo 'Mailer Error: ' . $mail->ErrorInfo;
    } else {
        echo 'Message has been sent';
    }
    ?>
但是输入密码,它就不喜欢了。而是像这样将代码打印到网页上

isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'rottenrobbie911@gmail.com'; // SMTP username $mail->Password = 'password';
// SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('yalnifcam2@gmail.com', 'Joe User'); $mail->Subject 
= 'GenericSubject'; $mail->Body = 'This is the HTML message body in bold!'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?> 
只是密码而已。当我输入密码时,它不起作用,但离开银行,它只是无法进行身份验证。

将端口号
587
用于
TLS

更改此
$mail->Port=465
$mail->Port=587

将端口号
587
用于
TLS


更改此
$mail->Port=465
$mail->Port=587

您可能也需要发布屏幕截图,但在这台特定的计算机上很难。如果Sahil的修复程序不起作用,我会的。如果您阅读错误消息链接到的故障排除指南,并根据PHPMailer提供的gmail示例编写代码,这会有所帮助。如果您设置
SMTPDebug=2
,您将获得有关问题所在的更多信息。还有,你为什么要包括SwiftMailer和PHPMailer?挑一个!你可能也需要发布截图,但在这台电脑上很难。如果Sahil的修复程序不起作用,我会的。如果您阅读错误消息链接到的故障排除指南,并根据PHPMailer提供的gmail示例编写代码,这会有所帮助。如果您设置
SMTPDebug=2
,您将获得有关问题所在的更多信息。还有,你为什么要包括SwiftMailer和PHPMailer?挑一个!不幸的是,它不起作用。问题似乎出在密码上。我改变了邮件服务器,当我没有输入密码时,比如:this$mail->password='';然后,它似乎可以工作,但无法进行身份验证。输入密码后,所有密码都无效。@Yalnix我原以为您使用的是正确的密码。不幸的是,密码无效。问题似乎出在密码上。我改变了邮件服务器,当我没有输入密码时,比如:this$mail->password='';然后,它似乎可以工作,但无法进行身份验证。输入密码后,所有密码都不起作用。@Yalnix我原以为您使用的是正确的密码。
isSMTP(); // Set mailer to use SMTP $mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers $mail->SMTPAuth = true; // Enable SMTP authentication $mail->Username = 'rottenrobbie911@gmail.com'; // SMTP username $mail->Password = 'password';
// SMTP password $mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted $mail->Port = 465; $mail->setFrom('from@example.com', 'Mailer'); $mail->addAddress('yalnifcam2@gmail.com', 'Joe User'); $mail->Subject 
= 'GenericSubject'; $mail->Body = 'This is the HTML message body in bold!'; if(!$mail->send()) { echo 'Message could not be sent.'; echo 'Mailer Error: ' . $mail->ErrorInfo; } else { echo 'Message has been sent'; } ?>