简体   繁体   English

无法使用phpmailer发送邮件

[英]Cant send mail with phpmailer

I had it totally working before, but I reinstalled ubuntu 13.10 on my server and now it doesnt work, my code is as follows: 我之前完全使用过它,但是我在服务器上重新安装了ubuntu 13.10,现在它不起作用了,我的代码如下:

require 'php/PHPMailer/PHPMailerAutoload.php';


$mail = new PHPMailer();

$mail->isSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'mail@gmail.com';
$mail->Password = 'pass';
$mail->setFrom('mail@gmail.com', 'First Last');
$mail->addAddress('mail2@hotmail.com', 'Random person');
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->msgHTML('prueba');

//send the message, check for errors
if (!$mail->send()) {
    echo 'Mailer Error: ' . $mail->ErrorInfo;
} else {
    echo "Message sent!";
}

mail, mail2 and pass are just safewords, they are valid addresses and password. mail,mail2和pass只是安全密码,它们是有效的地址和密码。

OpenSSL is installed and working with a temporary cert. 已安装OpenSSL并使用临时证书。

Any ideas of why it doesnt work now after Ubuntu 13.10 reinstall? 重新安装Ubuntu 13.10后为何现在不起作用的任何想法?

Forgot to tell, the error Im getting now is: 忘了告诉我,我现在遇到的错误是:

SMTP ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) SMTP connect() failed. SMTP错误:无法连接到服务器:php_network_getaddresses:getaddrinfo失败:名称或服务未知(0)SMTP connect()失败。 Mailer Error: SMTP connect() failed. 邮件错误:SMTP connect()失败。

It's most likely a firewall setting in Ubuntu... Try using SSL instead or follow the instructions below for further investigation... 这很可能是Ubuntu中的防火墙设置...尝试改用SSL或按照以下说明进行进一步的调查...

$mail->SMTPSecure = 'ssl';
$mail->Host       = "smtp.gmail.com";
$mail->Port       = 465;

The problem means you are unable to connect to port 587 on server smtp.gmail.com . 该问题意味着您无法连接到服务器smtp.gmail.com上的端口587。 Verify this using telnet: 使用telnet进行验证:

telnet smtp.gmail.com 587

(This works for me, so the server and port number are correct.) (这对我有用,因此服务器和端口号正确。)

Possible reasons for this to do not work from your location are: 从您的位置无法执行此操作的可能原因是:

  • Misconfigured proxy settings 错误配置的代理设置
  • A firewall at your location, which forbids to connect to this port number. 您所在位置的防火墙,禁止连接到该端口号。

If the telnet command above can connect, then you can rule out a problem with the firewall. 如果上面的telnet命令可以连接,则可以排除防火墙问题。 If it does not work, then it's most likely the firewall, which causes the problem. 如果不起作用,则很可能是引起问题的防火墙。

Also, find out the port number which is used with your other connection method. 另外,找出与您的其他连接方法一起使用的端口号。 Maybe that also works with TLS. 也许这也适用于TLS。

I installed php-pear with some others packages and it was solved: 我与其他一些软件包一起安装了php-pear,此问题已解决:

apt-get install php-pear pear install mail pear install Net_SMTP pear install Auth_SASL pear install mail_mime apt-get安装php-pear pear安装邮件pear安装Net_SMTP pear安装Auth_SASL pear安装mail_mime

I had the same problem. 我有同样的问题。 Turns out I didn't have sendmail installed on my server. 原来我的服务器上没有安装sendmail I installed sendmail from fedora repo and restarted apache server and it connected. 我从fedora repo安装了sendmail并重新启动了apache服务器,并且它已连接。

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

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