2

appfogでホストされているアプリケーションで電子メールを送信でき ません。次のコードを使用しています。このコードは、localhost では正常に動作しますが、appfog では失敗します。JPhpMailer 拡張 class.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();

`if ($tls) { if (!$this->smtp->StartTLS()) { throw new phpmailerException($this->Lang('tls')); の実行に失敗する phpMailer の行を次に示します。}

         //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

以下のコードは私のために働いています:

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 に答える
0

ステップ 1:- https://myaccount.google.com/security#signinに移動し、アプリ パスワードによってアプリパスワードが生成されます。

ステップ 2:- その 16 桁のパスワードを貼り付けます$mailer->Password

于 2016-10-12T14:26:09.343 に答える