我已经实现了网站的邮件功能,但是在发送电子邮件时出错。我已经将PHPMailer添加到我的网站并添加了代码,但是却收到此错误。也可以通过签入google与主机进行更改,但仍然收到相同的错误。
2019-07-06 06:55:56 CLIENT -> SERVER: EHLO website.com
2019-07-06 06:55:56 CLIENT -> SERVER: STARTTLS
SMTP Error: Could not connect to SMTP host.
2019-07-06 06:55:56 CLIENT -> SERVER: QUIT
SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
<?php
if(isset($_POST['submit_contact']))
{
require 'PHPMailer/PHPMailerAutoload.php';
$to = "XXXX@gmail.com";
$name = $_POST['firstname'];
$email = $_POST['email'];
$contact=$_POST['contact'];
$textarea = $_POST['textarea'];
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 1;
$mail->SMTPAuth = false;
$mail->SMTPSecure = 'none';
$mail->Host = "localhost";
$mail->Port = 25;
$mail->IsHTML(true);
$mail->Username = "XXXXX@gmail.com";
$mail->Password = "PASSXXX";
$mail->SSL=False;
$message = array();
$message[]= 'Name : '.trim($name).' ';
$message[]='Phone : '.trim($contact).' ';
$message[]='Email : '.trim($email).' ';
$message[]='Message : '.trim($textarea).' ';
$message = implode('<br/>', $message);
$mail->SetFrom($email);
$mail->Subject = 'Regarding Pure Gir Cow Milk';
$mail->Body = $message;
$mail->AddAddress($to);
if(!$mail->send()) {
$msg = "Error while sending email";
$msgclass = 'bg-danger';
} else {
$msg = 'Successfully Sent.';
$msgclass = 'bg-success';
}
}
?>
答案 0 :(得分:0)
这解决了我的问题。
$mail = new PHPMailer();
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->SMTPAuth = true;
$mail->SMTPSecure = 'none';
$mail->Host = "ssl://smtp.gmail.com";
$mail->Port = 465;
$mail->IsHTML(true);
$mail->Username = "xxxx@gmail.com";
$mail->Password = "xxxxx";
$from = $email; // Reply to this email
$mail->From = $from;
$mail->FromName = $name;