PHPMailer on remote host does't work

和自甴很熟 提交于 2020-01-25 18:01:44

问题


I'm working on a little e-cards project. I have to send emails from my remote server with PHPMailer.

localy I'm using this configuration (with my own Gmail email adress) and it works perfectly.

/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';
?>

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';
?>

Thanks again!


回答1:


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***';

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);

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***';



回答2:


You have not said how it's failing, which makes diagnosis difficult.

I really wouldn't recommend any service that uses authentication without encryption. There is no meaning to setting SMTPSecure to 'none' - just set it to an empty string (or don't set it at all) if you don't want SSL or TLS, and you only need to do that once (not twice as in your code).




回答3:


The other solutions did not work for me; this one did:

$mail->isSMTP();
$mail->Host = 'mailout.one.com';
$mail->SMTPAuth = false;                            // disable SMTP authentication
$mail->Username = '[your one.com-email]';
$mail->Password = '[your one.com-email password]';
$mail->SMTPSecure = '';                            // leave this blank!
$mail->Port = 25; 

Let me know if it helped you, too!



来源:https://stackoverflow.com/questions/27747645/phpmailer-on-remote-host-doest-work

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!