2

我无法在托管在appfog上的应用程序中发送电子邮件 我正在使用以下代码,该代码在 localhost 上运行良好,但在 appfog 上失败。JPhpMailer 扩展类.PhpMailer.php

                    $mailer = new JPhpMailer(true);
                    $mailer->IsSMTP();
                    $mailer->Mailer = "smtp";
                    //$mailer->SMTPSecure == 'tls'; 
                    $mailer->Host = 'ssl://smtp.gmail.com';
                    $mailer->Port = '465';
                    $mailer->SMTPAuth = true;
                    //$mailer->SMTPSecure = true; 
                    $mailer->Username = 'me@gmail.com';
                    $mailer->Password = 'zzzzzzz';
                    $mailer->SetFrom($to['from'], $to['from_name']); 
                    $mailer->AddAddress($to['to'],$to['to_name'] ); 
                    $mailer->Subject = $to['subject'];
                    $mailer->Body = $to['body'];
                    $mailer->Send();

这是 phpMailer 中执行失败的行`if ($tls) { if (!$this->smtp->StartTLS()) { throw new phpmailerException($this->Lang('tls')); }

         //We must resend HELO after tls negotiation
        $this->smtp->Hello($hello);
      }

       $connection = true;
      if ($this->SMTPAuth) {
         if (!$this->smtp->Authenticate($this->Username, $this->Password)) {
         **strong text throw new phpmailerException($this->Lang('authenticate')); **            }
      }
     }
   $index++;
    if (!$connection) {
       throw new phpmailerException($this->Lang('connect_host'));
     }
4

6 回答 6

6

The code below is working for me :

require("phpmailer/class.phpmailer.php");

$mail = new PHPMailer();

$mail->IsSMTP();                                      // set mailer to use SMTP
$mail->SMTPAuth = true;     // turn on SMTP authentication
$mail->SMTPSecure = "tls";
$mail->Host = "smtp.gmail.com";  // specify main and backup server
$mail->Port = 587;
$mail->Username = "myemail@gmail.com";  // SMTP username
$mail->Password = "mypass"; // SMTP password

$mail->From = "myemail@gmail.com";
$mail->FromName = "myname";
$mail->AddAddress("myaddress@gmail.com", "myname");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters
$mail->IsHTML(true);                                  // set email format to HTML

$mail->Subject = "Here is the subject";
$mail->Body    = "This is the HTML message body <b>in bold!</b>";
$mail->AltBody = "This is the body in plain text for non-HTML mail clients";

if(!$mail->Send())
{
   echo "Message could not be sent. <p>";
   echo "Mailer Error: " . $mail->ErrorInfo;
   exit;
}

echo "Message has been sent";
于 2013-01-10T10:22:45.910 回答
4

我遇到了同样的问题。为了让它工作,我必须去myaccount.google.com ->“连接的应用程序和网站”,然后将“允许不太安全的应用程序”设置为“开启”(靠近页面底部)。

希望它可以帮助某人

在此处输入图像描述

于 2016-08-23T15:46:02.560 回答
1

注册 appfog 后,我可以让 PHPMailer 使用以下内容。

我无法找到 JPHPMailer,尽管我怀疑这不是您的问题的原因,而是您将 ssl://smtp.gmail.com 作为主机的事实。

ini_set('display_errors', 1);
error_reporting(E_ALL);

include('class.phpmailer.php');
$mailer = new PHPMailer(true);
$mailer->IsSMTP();
$mailer->SMTPSecure = 'ssl';
$mailer->Host = 'smtp.gmail.com';
$mailer->Port = 465;
$mailer->SMTPAuth = true;
$mailer->Username = 'me@gmail.com';
$mailer->Password = 'password';
$mailer->SetFrom('me@gmail.com', 'Name'); 
$mailer->AddAddress('you@gmail.com'); 
$mailer->Subject = 'This is a test';
$mailer->Body = 'Test body';
$mailer->Send();

希望这可以帮助?

于 2013-01-10T09:20:31.033 回答
1

打印您的PHPMailer对象并检查PORT对象和您给出的PORT

echo "<pre>", print_r($mailer, true);
exit;
于 2016-01-30T04:26:35.660 回答
0

第 1 步:- 转到https://myaccount.google.com/security#signin然后应用密码生成应用密码

第 2 步:- 粘贴 16 位密码$mailer->Password

于 2016-10-12T14:26:09.343 回答
0

在大多数情况下,您需要创建两步验证并使用应用密码登录。

小提示:你应该仔细阅读 phpmailer 的调试信息。问题的答案可能有适当的链接。

我有这个:https ://support.google.com/mail/answer/7126229?visit_id=1-636190350518295662-3485238940&rd=2#cantsignin

于 2017-01-03T10:37:32.897 回答