phpMailer来自Heroku的gmail业务?

时间:2013-01-18 23:43:18

标签: php heroku gmail phpmailer

我一直在尝试设置谷歌商务电子邮件smtp。我用自己的电子邮件地址(username@mydomain.me)创建了一个帐户。这是由gmail托管的。

我在Heroku上使用phpMailer类。我已经取消注释了php.ini文件中的php_openssl.dll。

我一直收到这个错误:

ERROR: Failed to connect to server: php_network_getaddresses: getaddrinfo failed: Name or service not known (0) SMTP Error: Could not connect to SMTP host.

有谁知道这里出了什么问题?

 ...
 $mail->Host = "ssl://stmp.gmail.com";
 $mail->SMTPDebug  = 2;  
 $mail->SMTPAuth   = true;
 $mail->Port       = 587;
 $mail->SMTPSecure = 'ssl'; 
 $mail->Username   = "username@myDomain.me";
 $mail->Password   = "mypassword";
 $mail->SetFrom('username@myDomain.me', '...');
 $mail->AddReplyTo("an@email.co", '');
 $mail->Subject = '...';
 ...

2 个答案:

答案 0 :(得分:4)

想出来!诀窍是“tls”而不是ssl!

    $mail->IsSMTP(); // telling the class to use SMTP
    $mail->Host       = "mail.mydomain.me"; // SMTP server
    $mail->SMTPDebug  = 2;                     // enables SMTP debug information (for testing)
                                               // 1 = errors and messages
                                               // 2 = messages only
    $mail->SMTPAuth   = true;                  // enable SMTP authentication
    $mail->SMTPSecure = "tls";                 // sets the prefix to the servier
    $mail->Host       = "smtp.gmail.com";      // sets GMAIL as the SMTP server
    $mail->Port       = 587;                   // set the SMTP port for the GMAIL server
    $mail->Username   = "name@mydomain.me";  // GMAIL username
    $mail->Password   = "pass";            // GMAIL password

答案 1 :(得分:0)

试试这个

$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->SMTPSecure = "ssl";
$mail->Port = 465; 

应该有效

参考: - 1 2