Php SMTP错误:无法连接到SMTP主机。失败
我在通过php mailer发送邮件时遇到问题,我可以轻松地在localhost(Wampp)上发送电子邮件,但在live Server上我收到错误: SMTP错误:无法连接到SMTP主机。失败Php SMTP错误:无法连接到SMTP主机。失败,php,email,phpmailer,Php,Email,Phpmailer,我在通过php mailer发送邮件时遇到问题,我可以轻松地在localhost(Wampp)上发送电子邮件,但在live Server上我收到错误: SMTP错误:无法连接到SMTP主机。失败 尝试设置$mail->SMTPSecure='tls'而不是'ssl'。顺便说一句,你说你“创建”了一个php.ini?应该已经有一个PHP在服务器上使用。您的服务器是Windows服务器还是Linux服务器.dll-文件仅限Windows。即使在tls之后也无法工作!!我不知道是windows还是li
尝试设置$mail->SMTPSecure='tls'代码>而不是'ssl'
。顺便说一句,你说你“创建”了一个php.ini?应该已经有一个PHP在服务器上使用。您的服务器是Windows服务器还是Linux服务器.dll
-文件仅限Windows。即使在tls之后也无法工作!!我不知道是windows还是linux!你不知道服务器是运行Windows还是Linux?您是如何以及在何处创建/编辑php.ini
-文件的?你如何连接到服务器?我有cpanel的登录id和密码,它是别人的共享托管帐户。如果你不想费心把你的代码建立在PHPMailer提供的测试代码上,也不想费心阅读文档、阅读错误消息或运行一个不到几年的版本,许多其他网站也在那里,我没有同情心。
<?php
if (isset($_POST['submit'])) {
# code...
$customeremail="*************";
$message=
'Full Name: '.$_POST['name'].'<br />
Subject: '.$_POST['subject'].'<br />
Phone: '.$_POST['phone'].'<br />
Email: '.$_POST['email'].'<br />
Comments: '.$_POST['message'].'
';
require "phpmailer/class.phpmailer.php"; //include phpmailer class
// Instantiate Class
$mail = new PHPMailer();
// Set up SMTP
$mail->IsSMTP(); // Sets up a SMTP connection
$mail->SMTPAuth = true; // Connection with the SMTP does require authorization
$mail->SMTPSecure = "ssl"; // Connect using a TLS connection
$mail->Host = "smtp.gmail.com"; //Gmail SMTP server address
$mail->Port = 465; //Gmail SMTP port
$mail->Encoding = '7bit';
// Authentication
$mail->Username = "******"; // Your full Gmail address
$mail->Password = "******"; // Your Gmail password
// Compose
$mail->From = "*************";
$mail->FromName = "**********";
$mail->Subject = "DRIVER AND CAR DETAILS"; // Subject (which isn't required)
$mail->MsgHTML($message);
// Send To
$mail->AddAddress($customeremail, "Recipient Name"); // Where to send it - Recipient
$result = $mail->Send(); // Send!
if(!$mail->Send()) {
echo 'Message was not sent.';
echo 'Mailer error: ' . $mail->ErrorInfo;
} else {
echo 'Message has been sent.';
}
?>