简体   繁体   English

php mailer SMTP错误:无法连接到SMTP主机

[英]php mailer SMTP Error: Could not connect to SMTP host

I have hosted my website on Plesk Hosting and was working on submitting the contact form. 我的网站托管在Plesk Hosting上,并且正在提交联系表格。 Installed PHP Mailer using composer. 使用composer安装了PHP Mailer。 First I tried to send email using Gmail SMPT server it worked fine Second I tried to send email using my webhosting SMTP Server it is not working for me 首先,我尝试使用Gmail SMPT服务器发送电子邮件,但工作正常;其次,我尝试使用我的网络托管SMTP服务器发送电子邮件,但对我来说不起作用

$mail->Host = 'webmail.abc.in';      //host
$mail->SMTPAuth = false;              
$mail->Username = '******@abc.in';    
$mail->Password = '*******';              
$mail->SMTPSecure = 'tls';
$mail->Port = 25;      

I tested the SMPT server using SMTPER . 我使用SMTPER测试了SMPT服务器。 it could send email using same credentials. 它可以使用相同的凭据发送电子邮件。

i dont know where the issue is.. 我不知道问题在哪里。

is there any other library other then phpmailer?? 除了phpmailer之外,还有其他库吗?

$mail->SMTPAuth = true;

As simple as that, I think. 我想就这么简单。

You said you have tested the credentials on SMTPer, 您说您已经在SMTPer上测试了凭据,

I'm sure you checked the "Use authentication" checkbox. 我确定您已选中“使用身份验证”复选框。

Maybe you thought you could make it false because you are not using SSL, 也许您以为可以将其设为虚假,因为您没有使用SSL,

But this is about user authentication, not about encrypted communication. 但这与用户身份验证有关,与加密通信无关。

This is a example of of code I'm using with gmail. 这是我与gmail一起使用的代码示例。 Tested it with webhosting SMTP and worked as well. 使用webhosting SMTP对其进行了测试,并且运行良好。

`           $mailMsg = ADD_MAIL_MESSAGE_HERE;
            $mailto = ADD_TO_ADDRESS_HERE;
            $mail = new PHPMailer\PHPMailer\PHPMailer();
            $mail->IsSmtp();
            $mail->SMTPDebug = 0;
            $mail->SMTPAuth = true;
            $mail->SMTPSecure = 'ssl';
            $mail->Host = 'smtp.gmail.com';
            $mail->Port = 465;
            $mail->IsHTML(true);
            $mail->CharSet = 'UTF-8';
            $mail->Username = ADD_USERNAME_HERE;
            $mail->Password = ADD_PASSWORD_HERE;
            $mail->SetFrom(ADD_FROM_ADDRESS_HERE);
            //-------------------------------------------
            $mail->Subject = ADD_MAIL_SUBJECT_HERE;
            $mail->Body = $mailMsg;
            $mail->AddAddress($mailto);
            $mail->SMTPOptions = array(
                'ssl' => array(
                    'verify_peer' => false,
                    'verify_peer_name' => false,
                    'allow_self_signed' => true
                )
            );
`

Are you using a Shared Hosting with Plesk? 您是否正在使用Plesk的共享主机? If yes, then this can probably be a port block issue (exact reason you will get only in the maillog). 如果是,那么这很可能是端口阻塞的问题(确切原因是您只会在邮件日志中看到)。 Looking at your code, I can see that in case of your local SMTP testing you are using port 25 while in case of Gmail it's 465. 查看您的代码,我可以看到在进行本地SMTP测试的情况下,您使用的端口是25,而在Gmail中的端口是465。

By default, most of the shared hosting providers block the outgoing SMTP connection on port 25. This is done in order to protect the network and infrastructure from Spamming. 默认情况下,大多数共享主机提供商在端口25上阻止传出SMTP连接。这样做是为了保护网络和基础结构免受垃圾邮件的侵害。 If this is the case, then you need to contact their support to unblock the port or use some port free mode of email sending. 如果是这种情况,则您需要与他们的支持人员联系以解除阻止端口或使用电子邮件发送的某些无端口模式。 Means instead of connecting over SMTP, connect over HTTP API for sending emails. 意味着不要通过SMTP进行连接,而是通过HTTP API进行连接以发送电子邮件。

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

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