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

时间:2017-03-20 11:01:50

标签: 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 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';
    }
    ?>

当我在没有密码的情况下运行我的代码时,会出现:

    /var/www/html/mail.php /var/www/html/vendor/autoload.php /var/www/html/vendor/composer/autoload_real.php /var/www/html/vendor/composer/ClassLoader.php /var/www/html/vendor/composer/autoload_static.php /var/www/html/vendor/guzzlehttp/promises/src/functions_include.php /var/www/html/vendor/guzzlehttp/promises/src/functions.php /var/www/html/vendor/guzzlehttp/psr7/src/functions_include.php /var/www/html/vendor/guzzlehttp/psr7/src/functions.php /var/www/html/vendor/paragonie/random_compat/lib/random.php /var/www/html/vendor/guzzlehttp/guzzle/src/functions_include.php /var/www/html/vendor/guzzlehttp/guzzle/src/functions.php /var/www/html/vendor/sendgrid/sendgrid/lib/SendGrid.php /var/www/html/vendor/sendgrid/sendgrid/lib/helpers/mail/Mail.php /var/www/html/vendor/swiftmailer/swiftmailer/lib/swift_required.php /var/www/html/vendor/swiftmailer/swiftmailer/lib/classes/Swift.php
    Message could not be sent.Mailer Error: SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting

但是输入密码并且不喜欢它。而是将代码打印到网页上。

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'; } ?> 

这只是密码。当我输入密码时,它不起作用,但保留银行并且无法进行身份验证。

1 个答案:

答案 0 :(得分:0)

Reference gmail smtp settings

587使用端口号TLS

将此$mail->Port = 465;更改为$mail->Port = 587;