远程主机上的PHPMailer不起作用 [英] PHPMailer on remote host does't work
问题描述
我正在做一个小小的电子贺卡项目. 我必须使用PHPMailer从远程服务器发送电子邮件.
I'm working on a little e-cards project. I have to send emails from my remote server with PHPMailer.
localy我正在使用此配置(具有我自己的Gmail电子邮件地址),并且可以完美运行.
localy I'm using this configuration (with my own Gmail email adress) and it works perfectly.
/ssi/mail.config.php
/ssi/mail.config.php
<?php
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'smtp.gmail.com';
$mail->Port = '587';
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'private@gmail.com';
$mail->Password = '***secret***';
$mail->SMTPSecure = 'tls';
?>
在我的远程服务器(托管在one.com上)上,我为该域创建了一个电子邮件帐户. 我像帮助台所说的那样更改了主机和端口...但是我无法使其远程运行.
On my remote server (hosted on one.com) I have created an email account for the domain. I changed the host and the port like the helpdesk said ... but I don't get it to work remotly.
<?php
'ssi/mail.config.php'
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'send.one.com';
$mail->Port = '25';
$mail->SMTPSecure = 'none';
$mail->SMTPAuth = true;
$mail->Username = 'ecards@iveweygers.be';
$mail->Password = '***secret***';
$mail->SMTPSecure = 'none';
?>
再次感谢!
推荐答案
在one.com页面上,这有一些问题.对于smtp,他们说使用带有SSL加密的端口465.因此,您的代码应为:
Looking at the one.com page, there are a few things wrong with this. For smtp they say to use Port 465 with SSL encryption. So, your code should be:
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8'; // You can remove this line, utf-8 is the default.
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'send.one.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'ecards@iveweygers.be';
$mail->Password = '***secret***';
同样值得注意的是-我花了很长时间才找到的东西:我的SMTP服务器需要身份验证才能发送电子邮件.我以为SMTPAuth = true;
可以解决这个问题,但事实并非如此.我注意到one.com也是如此-也就是说,他们告诉您单击Outlook中的按钮,该按钮表示您的传出服务器需要身份验证.
Also worth noting -- and something that it took me a LONG time to find: My SMTP server required authentication to send an email. I assumed that the SMTPAuth = true;
took care of that but it did not. I noticed that one.com does as well -- i.e. they tell you to click the button in Outlook that says that your outgoing server requires authentication.
通过将其放在文件的顶部,终于使它起作用:
I finally got it to work by putting this at the top of my file:
$pop = new POP3();
$pop->Authorise("send.one.com", 465, 30, "ecards@iveweygers.be", "***secret_password***", 1);
负责身份验证.然后,您可以进入$mail = new PHPMailer(true)
并设置所有参数并发送邮件.
That takes care of the authentication. Then you can jump into the $mail = new PHPMailer(true)
and setting all of your parameters and sending the mail.
因此您的整个文件应如下所示:
So your entire file should look like this:
$pop = new POP3();
$pop->Authorise("send.one.com", 465, 30, "ecards@iveweygers.be", "***secret_password***", 1);
$mail = new PHPMailer(true);
$mail->CharSet = 'utf-8'; // You can remove this line, utf-8 is the default.
$mail->SMTPDebug = 2;
$mail->isSMTP();
$mail->Host = 'send.one.com';
$mail->Port = 465;
$mail->SMTPSecure = 'ssl';
$mail->SMTPAuth = true;
$mail->Username = 'ecards@iveweygers.be';
$mail->Password = '***secret***';
这篇关于远程主机上的PHPMailer不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!