2

PHPMailerを使用して自分のWebサイトに連絡フォームを作成しようとしています。設定に問題があります。SMTPホストとしてG-mailを使用しようとしています。誰かがこれをトラブルシューティングするのを手伝ってくれるかどうか疑問に思いましたか?

これは私のメーラーコードです:

<?php
require("class.phpmailer.php");
require("class.smtp.php");

$mail = new PHPMailer();

$mail->IsSMTP();   
$mail->SMTPAuth = true;     // turn on SMTP authentication      
$mail->SMTPSecure = 'ssl'; // secure transfer enabled REQUIRED for GMail        
$mail->Host = 'smtp.gmail.com';
$mail->Port = 467;  

$mail->Username = "validmail@gmail.com";  // SMTP username
$mail->Password = "workingpassword"; // SMTP password

$mail->From = "validmail@gmail.com";
$mail->FromName = "Mailer";
$mail->AddAddress("josh@example.net", "Josh Adams");
$mail->AddAddress("ellen@example.com");                  // name is optional
$mail->AddReplyTo("info@example.com", "Information");

$mail->WordWrap = 50;                                 // set word wrap to 50 characters


// $mail->AddAttachment("/var/tmp/file.tar.gz");         // add attachments
   // $mail->AddAttachment("/tmp/image.jpg", "new.jpg");    // optional name
    $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";
?>

エラーメッセージ:

Message could not be sent.
Mailer Error: The following From address failed: validmail@gmail.com
4

7 に答える 7

7

この Q の情報を見て試してみましたか?

PHPMailer: SMTP エラー: SMTP ホストに接続できませんでした

特に、これは追加情報を提供しますか?

$mail->SMTPDebug = 1;
于 2012-06-11T14:27:18.117 に答える
2

smtp.gmail.com では、SSL とポート 587 または 465 を使用する必要があります。

設定ページを参照してください: http://support.google.com/mail/bin/answer.py?hl=en&answer=13287

于 2012-06-11T14:29:47.093 に答える
1

Windows で PHP を実行していますか? 次に、これが役立つ場合があります:

http://www.devcha.com/2010/01/php-fsockopen-unable-to-connect-ssl.html

于 2012-06-11T14:38:40.163 に答える
1

同じエラーが発生しました。問題は、「boy333@in**」アカウントから「girl333@in**」のふりをしてメールを送信しようとしたことです。私はちょうど変更しました

$mail->From = 'girl333@in**'

ユーザー名に私は実際に接続していました。だから私は次のように変更しました:

$mail->From = 'boy333@in**'

アイデアは、これら 2 つのフィールドが同じユーザー名を持つということです。

$mail->Username   = "boy333";
$mail->From = 'boy333@in**';
于 2013-10-27T21:25:13.847 に答える
0
ping smtp.gmail.com

何らかの理由で、Google は SMTP リクエストを gmail-smtp-msa.l.google.com にリダイレクトします。

PING gmail-smtp-msa.l.google.com (74.125.133.108): 56 data bytes
64 bytes from 74.125.133.108: icmp_seq=0 ttl=43 time=72.636 ms
64 bytes from 74.125.133.108: icmp_seq=1 ttl=43 time=68.841 ms
64 bytes from 74.125.133.108: icmp_seq=2 ttl=43 time=68.500 ms

PHPMailer はリダイレクトに従わないため、最終的な宛先を設定に入れる必要があります。また、そのフィールドを空白のままにして、SMTPSecure を使用せずに電子メールを送信しようとすることもできます。

$mail->Host = 'gmail-smtp-msa.l.google.com';  
$mail->SMTPAuth = true;                            
$mail->Username = 'email';   
$mail->Password = 'password';    
$mail->SMTPSecure = '';   
$mail->Port = 25;  
于 2016-02-15T16:38:13.657 に答える
0

gsuite のメールの場合は、次の 2 つの手順を確認してください: https://support.google.com/a/answer/6260879?hl=en https://accounts.google.com/DisplayUnlockCaptcha

PHP メール設定; PHPMailer バージョン 5.2.22 チェック class.phpmailer.php,

  var $Host = 'smtp.gmail.com';
  var $Port = 465;
  var $Helo ='domain.net';
  public $SMTPSecure = 'ssl';
  public $SMTPAutoTLS = true;
  public $SMTPAuth = true;
  public $SMTPOptions = array();
  public $Username = 'gmail-username';//or domain credentials on google mail
  public $Password = 'gmail-password';
  public $Timeout = 10;
  public $SMTPDebug = true;

メール送信php

<?php
require('PHPMailer/class.phpmailer.php');
require('PHPMailer/class.smtp.php');

$headers = "Content-Type: text/html; charset=UTF-8";    
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->CharSet="SET NAMES UTF8";
$mail->SMTPDebug  = 0;
$mail->CharSet="utf8";
$mail->Debugoutput = 'html';
$mail->host       = "smtp.gmail.com";
$mail->port       = 465;
$mail->smtpauth   = true;
$mail->smtpsecure = 'ssl';
$mail->username   = "gmail-username"; //or domain credentials on google mail
$mail->password   = "gmail-password";
$mail->SetFrom('from-email', 'from-name');
$mail->AddAddress('to-address', 'to-address');
$mail->Body = 'your-text'; //emailbody
if(!$mail->Send()) 
        {
            mysql_close();
        echo "<script>alert('Error: " . $mail->ErrorInfo."');</script>";
        } 
        else 
        {
        mysql_close();
        echo "<script>alert('success');</script>";
        }

?>

これは私の仕事です。それが役に立てば幸い。

于 2017-03-17T08:59:11.843 に答える