联系表单,phpmailer()和gmailaddress的问题


Problems with contact form, phpmailer() and gmailadress

我有问题的联系形式,因此我读到phpmailer是非常有用的。不幸的是,我已经被困了好几个小时了,我不知道怎么再往前走了。

我想测试是否可以发送电子邮件(之后我想将电子邮件连接到表单提交,但到目前为止还没有成功。)我使用的是PHPmailer 5.2.0,我使用下面的代码(同时使用WAMPSERVER进行测试)。有人知道我应该调整什么吗?

我已经用了很多例子(包括从stackoverflow,但我只是错过了一些东西。你知道哪里出错了吗?每次我得到错误:

SMTP -> ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Er is een onherstelbare fout opgetreden tijdens het zoeken in de database. (0) 
SMTP Error: Could not connect to SMTP host. Mailer Error: SMTP Error: Could not connect to SMTP host.

提前感谢!!

<?php
require_once('class.phpmailer.php');
include("class.smtp.php"); // optional, gets called from within class.phpmailer.php if not already loaded
$mail             = new PHPMailer();
$body             = file_get_contents('contactformulier.html');
//$body             = eregi_replace("[']",'',$body);
$mail->IsSMTP(); // telling the class to use SMTP
$mail->Host       = "test@gmail.com"; // SMTP server
$mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                           // 1 = errors and messages
                                           // 2 = messages only
$mail->SMTPAuth   = true;                  // enable SMTP authentication
$mail->Host       = "test@gmail.com"; // sets the SMTP server
$mail->Port       = 26;                    // set the SMTP port for the GMAIL server
$mail->Username   = "test@gmail.com"; // SMTP account username
$mail->Password   = "password";        // SMTP account password
$mail->SetFrom('test@gmail.com', 'First Last');
$mail->AddReplyTo("test@gmail.com","First Last");
$mail->Subject    = "PHPMailer Test Subject via smtp, basic with authentication";
$mail->AltBody    = "To view the message, please use an HTML compatible email viewer!"; // optional, comment out and test
$mail->MsgHTML($body);
$address = "test@gmail.com";
$mail->AddAddress($address, "John Doe");

if(!$mail->Send()) {
  echo "Mailer Error: " . $mail->ErrorInfo;
} else {
  echo "Message sent!";
}
?>

正如Mike评论的那样,您使用了一些非常奇怪的值。下面的例子来自PHPMailer的repo,它主要涉及这些设置:

$mail->Host       = 'smtp.gmail.com';
$mail->Port       = 587;
$mail->SMTPSecure = 'tls';

你也在使用旧版本的PHPMailer -自那个版本以来已经修复了很多错误,所以请获取最新版本。

否则,简单的连接失败通常归结为DNS或本地网络问题,而不是PHPMailer中的任何问题。

感谢大家的帮助,现在邮件工作正常!我有一个错误的端口和主机(我问我的提供商)。

还有,你们知道发完邮件后怎么回到网页吗?