私はコードに変更を加えましたが効果はありません。コード自体はエラーを返しませんが、代わりに成功メッセージを返します。私は私のリレーとしてgmailを使用しています。phpmailer 6.0成功メッセージですが、メールをリレーとしてGmailを使用して受信していません
P.Sさん、私は$mail->IsSMTP();
とコメントしました。私はこれを修正に使ったのと同じような質問をしました。「接続に失敗しました」というエラーが表示されました。
私はPHPmailer 6.0を使用しています。ここで
私のコードです:
<?php
require_once('vendor/autoload.php');
define('GUSER', '[email protected]'); // GMail username
define('GPWD', '*********'); // GMail password
function smtpmailer($to, $from, $from_name, $subject, $body) {
\t global $error;
\t $mail = new PHPMailer\PHPMailer\PHPMailer(true); // create a new object
\t //$mail->IsSMTP(); // enable SMTP
\t $mail->SMTPDebug = 4; // debugging: 1 = errors and messages, 2 = messages only
\t $mail->SMTPAuth = true; // authentication enabled
\t $mail->SMTPSecure = 'tls'; // secure transfer enabled REQUIRED for GMail
\t $mail->Host = 'smtp.gmail.com';
\t $mail->Port = 465;
\t $mail->Username = GUSER;
\t $mail->Password = GPWD;
\t $mail->SetFrom($from, $from_name);
\t $mail->Subject = $subject;
\t $mail->Body = $body;
\t $mail->AddAddress($to);
\t if(!$mail->Send()) {
\t \t $error = 'Mail error: '.$mail->ErrorInfo;
\t \t return false;
\t } else {
\t \t $error = 'Message sent!';
\t \t return true;
\t }
}
smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!');
if (smtpmailer('[email protected]', '[email protected]', 'yourName', 'test mail message', 'Hello World!')) {
\t // do something
}
if (!empty($error)) echo $error;
?>
私は$mail->IsSMTP();
のコメントを解除した場合、私は、このエラーログを取得:
2017-12-27 07:58:54 Connection: opening to smtp.gmail.com:465, timeout=300, options=array() 2017-12-27 07:58:54 Connection failed. Error #2: stream_socket_client(): unable to connect to smtp.gmail.com:465 (Network is unreachable) [/srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/SMTP.php line 325] 2017-12-27 07:58:54 SMTP ERROR: Failed to connect to server: Network is unreachable (101) SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting
致命的なエラー:キャッチされないphpmailerの\ phpmailerの\例外:SMTPを通信失敗。 https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting /srv/disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php:1726スタックトレース:#0 /srv/disk2/2564570/www/consorttest.dx.am/ PHPMailer \ PHPMailer \ PHPMailer-> smtpSend( 'Date:Wed、27 D ...'、 'Hello World!\ r \ n')#1/srv /disk2/2564570/www/consorttest.dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php(1320):PHPMailer \ PHPMailer \ PHPMailer-> postSend()#2/srv/disk2/2564570/www/consorttest .dx.am/mailtest.php(23):PHPMailer \ PHPMailer \ PHPMailer-> send()#3 /srv/disk2/2564570/www/consorttest.dx.am/mailtest.php(32):smtpmailer( 'に/ srv/disk2/2564570/www/consorttestにスローされた#4 {メイン}}、 'from @mail.com'、 '[email protected]'、 'yourName'、 'test mail messa ...'、 'Hello World! .dx.am/vendor/phpmailer/phpmailer/src/PHPMailer.php on line 1726