简体   繁体   English

PHPMailer $ mail-> send()在页面上显示结果

[英]PHPMailer $mail->send() showing results on page

I have PHPMailer working through Gmail. 我让PHPMailer通过Gmail工作。 I've sent emails to myself to test that it's working, and it is. 我已经给自己发送了电子邮件,以测试它是否正常工作。 The user submits a signup form (very basic setup) on index.php, which then triggers sending the email. 用户在index.php上提交一个注册表单(非常基本的设置),然后触发发送电子邮件。

My problem is that after submitting the form, it "echoes" to the page the process that it's going through: to give a sense of it, here's the start (3000 characters so I'm only including a bit): 我的问题是,提交表单后,它会将页面所经历的过程“呼应”到页面上:为了给它一个感觉,这是开始(3000个字符,所以我只包含了一点):

2017-03-01 21:25:36 Connection: opening to smtp.gmail.com:587, timeout=300, options=array ( ) 2017-03-01 21:25:36 Connection: opened 2017-03-01 21:25:36 SERVER -> CLIENT: 220 smtp.gmail.com ...

This shows up directly on the page. 这直接显示在页面上。 I'm sure I could get around it by redirecting to another page on success, but it seems much easier to simply not print all of the information to the page in the first place. 我确信我可以通过成功重定向到另一个页面来解决这个问题,但是似乎一开始就不简单地将所有信息打印到页面上似乎要容易得多。 I've tested my code and it's definitely the $mail->send(); 我已经测试了我的代码,绝对是$mail->send(); command that's triggering it. 触发它的命令。

Here's the code I'm using to call PHPMailer (it's inside <?php and ?> tags. 这是我用来调用PHPMailer的代码(位于<?php?>标记内。

require_once "phpmailer/PHPMailerAutoload.php";

$mail = new PHPMailer;

$mail->SMTPDebug = 3;
$mail->isSMTP();                                   
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;                               
$mail->Username = "myemailaddress@gmail.com";                 
$mail->Password = "mypassword";                           
$mail->SMTPSecure = "tls";
$mail->Port = 587;     

$mail->From = "myemailaddress@gmail.com";
$mail->FromName = "my name";
[![enter image description here][1]][1]
$mail->addAddress("towhoever@gmail.com", "their name");

$mail->isHTML(true);

$mail->Subject = "Testing email for phpmailer";
$mail->Body = "<i>Mail body in HTML</i>. It worked!";
$mail->AltBody = "This is the plain text version of the email content. Also, it worked!";

if($mail->send()) 
{
    echo "Message has been sent successfully";
} 
else 
{
    echo "Mailer Error: " . $mail->ErrorInfo;
}

Misc. 杂项 system information if it helps: I'm using XAMPP on Windows 10, running in localhost. 系统信息(如果有帮助):我在Windows 10上使用XAMPP,在本地主机上运行。 I'm connected to my Gmail account. 我已连接到我的Gmail帐户。

Here's what the problem looks like on the page (I didn't screenshot much as I'm unsure how much is sensitive information): 这是页面上问题的样子(我不确定截图多少,因为我不确定敏感信息有多少): 问题的屏幕截图

PhpMailer have option to debug. PhpMailer有调试选项。

$mail->SMTPDebug  // enables SMTP debug information (for testing)

// 1 = errors and messages

// 2 = messages only

Comment $mail->SMTPDebug = 3; 注释$ mail-> SMTPDebug = 3; in the code. 在代码中。

$mail->SMTPDebug = 0; $ mail-> SMTPDebug = 0; //after all functions work proper set to 0; //所有功能正常工作后,将其设置为0;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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