質問をすることでしか得られない、回答やアドバイスがある。

15分調べてもわからないことは、質問しよう!

新規登録して質問してみよう
ただいま回答率
85.47%
PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

メール

メールは、コンピュータネットワークを利用し、 情報等を交換する手段のことです。

XAMPP

XAMPP(ザンプ)は、ウェブアプリケーションの実行に必要なフリーソフトウェアをパッケージングしたApacheディストリビューションです。 XAMPPひとつインストールするだけで、Apache、MySQL、PHP、Perlなどのソフトウェアと、 phpMyAdminなどの管理ツール、SQLiteなどのソフトウェアやライブラリモジュールなどを利用することが可能です。

Q&A

解決済

2回答

3787閲覧

PHPMailerを使ってXAMPPローカル環境上でメールを送信したい

退会済みユーザー

退会済みユーザー

総合スコア0

PHP

PHPは、Webサイト構築に特化して開発されたプログラミング言語です。大きな特徴のひとつは、HTMLに直接プログラムを埋め込むことができるという点です。PHPを用いることで、HTMLを動的コンテンツとして出力できます。HTMLがそのままブラウザに表示されるのに対し、PHPプログラムはサーバ側で実行された結果がブラウザに表示されるため、PHPスクリプトは「サーバサイドスクリプト」と呼ばれています。

メール

メールは、コンピュータネットワークを利用し、 情報等を交換する手段のことです。

XAMPP

XAMPP(ザンプ)は、ウェブアプリケーションの実行に必要なフリーソフトウェアをパッケージングしたApacheディストリビューションです。 XAMPPひとつインストールするだけで、Apache、MySQL、PHP、Perlなどのソフトウェアと、 phpMyAdminなどの管理ツール、SQLiteなどのソフトウェアやライブラリモジュールなどを利用することが可能です。

0グッド

0クリップ

投稿2021/12/21 16:47

編集2021/12/22 07:44

前提・実現したいこと

XAMPPのローカル環境上で、PHPMailerを使ってyahooメールからgmailにメールを送信したい。

発生している問題・エラーメッセージ

送信エラー'SMTP connect() failed. https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting'

該当のソースコード

PHP

1//mail.php 2 3<?php 4 require 'php-library/Exception.php'; 5 require 'php-library/PHPMailer.php'; 6 require 'php-library/SMTP.php'; 7 8 use PHPMailer\PHPMailer\PHPMailer; 9 10 /** メールの送信テスト */ 11 12 /// メーラーインスタンス作成 13 $mailer = new PHPMailer(); 14 15 /// 文字コード 16 $mailer->CharSet = 'UTF-8'; 17 $mailer->Encoding = '7bit'; 18 19 /// SMTPサーバーを利用する 20 $mailer->IsSMTP(); 21 $mailer->SMTPAuth = true; 22 23 /// SMTPサーバー 24 $mailer->Host = 'smtp.mail.yahoo.co.jp'; 25 /// 送信元のユーザー名 26 $mailer->Username = 'hoge'; 27 /// 送信元のパスワード 28 $mailer->Password = 'hogehoge'; 29 /// ポート番号 30 $mailer->Port = 465; 31 32 /// 送信元メルアド 33 $mailer->From = 'hoge@yahoo.co.jp'; 34 /// 送信者名 35 $mailer->FromName = 'テスト送信'; 36 37 /// 送信先と件名・本文を設定してテスト送信 38 /// 送信先アドレス 39 $mailer->addAddress( 'hoge@gmail.com' ); 40 /// メール件名 41 $mailer->Subject = 'テスト送信'; 42 /// メール本文 43 $mailer->Body = 'こんにちは、テスト送信です。'; 44 /// メール送信 45 $result = $mailer->send(); 46 47 if ( $result ) { 48 print_r('送信成功!!'); 49 } else { 50 print_r('送信エラー'); 51 /// エラー内容全出力 52 var_export($mailer->ErrorInfo); 53 }

PHP

1//sendmail.ini 2 3; configuration for fake sendmail 4 5; if this file doesn't exist, sendmail.exe will look for the settings in 6; the registry, under HKLM\Software\Sendmail 7 8[sendmail] 9 10; you must change mail.mydomain.com to your smtp server, 11; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup) 12; emails delivered via IIS's pickup directory cause sendmail to 13; run quicker, but you won't get error messages back to the calling 14; application. 15 16smtp_server=mail.mydomain.com 17 18; smtp port (normally 25) 19 20smtp_port=25 21 22; SMTPS (SSL) support 23; auto = use SSL for port 465, otherwise try to use TLS 24; ssl = alway use SSL 25; tls = always use TLS 26; none = never try to use SSL 27 28smtp_ssl=auto 29 30; the default domain for this server will be read from the registry 31; this will be appended to email addresses when one isn't provided 32; if you want to override the value in the registry, uncomment and modify 33 34;default_domain=mydomain.com 35 36; log smtp errors to error.log (defaults to same directory as sendmail.exe) 37; uncomment to enable logging 38 39error_logfile=error.log 40 41; create debug log as debug.log (defaults to same directory as sendmail.exe) 42; uncomment to enable debugging 43 44;debug_logfile=debug.log 45 46; if your smtp server requires authentication, modify the following two lines 47 48auth_username= 49auth_password= 50 51; if your smtp server uses pop3 before smtp authentication, modify the 52; following three lines. do not enable unless it is required. 53 54pop3_server= 55pop3_username= 56pop3_password= 57 58; force the sender to always be the following email address 59; this will only affect the "MAIL FROM" command, it won't modify 60; the "From: " header of the message content 61 62force_sender= 63 64; force the sender to always be the following email address 65; this will only affect the "RCTP TO" command, it won't modify 66; the "To: " header of the message content 67 68force_recipient= 69 70; sendmail will use your hostname and your default_domain in the ehlo/helo 71; smtp greeting. you can manually set the ehlo/helo name if required 72 73hostname=

試したこと

ポート番号は25, 587, 465を試しましたが、すべて同じエラーメッセージが表示されます。
元々はPHPMailerを使わず、"php.ini"と"sendmail.ini"ファイルの設定を触っていたのですが、「Message is missing recipient's address」というエラーログが出てきて断念。PHPMailerを導入してみたところ、上記なようなエラーが表示され、やはりうまくいきません。

補足情報(FW/ツールのバージョンなど)

Windows10 XAMPP環境。ライブラリにPHPMailerを使用。
プログラミング初心者で、2日ほど考えても分からず投稿させていただきました。ご回答いただけると嬉しいです。よろしくお願いいたします。

気になる質問をクリップする

クリップした質問は、後からいつでもMYページで確認できます。

またクリップした質問に回答があった際、通知やメールを受け取ることができます。

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

退会済みユーザー

退会済みユーザー

2021/12/22 04:57

>>m.ts10806さん 一応、そのサイトを確認してポート番号を設定したのですが…。 ちなみに初歩的な質問となって申し訳ないのですが、参照する場所は「送信メール(SMTP)ポート番号 465」間違いないでしょうか? >>te2jiさん ありがとうございます。確認してみます。
FKM

2021/12/22 06:43

使用しているxamppのバージョンは何でしょうか?あとsendmail.iniの設定はどうなっていますか?
退会済みユーザー

退会済みユーザー

2021/12/22 07:47

XAMPPのバージョンはv3.3.0です。質問にsendmail.iniのソースコードを追加させていただきました。 PHPMailerのライブラリを利用する前に、すべてデフォルトの設定に戻しています。
FKM

2021/12/22 07:50

$mailer->IsSMTP(); ここを $mailer->isSMTP();に変えてみたらどうなりますか?
guest

回答2

0

ベストアンサー

Yahooメール>設定>IMAP/POP/SMTPアクセス>Yahoo! JAPAN公式サービス以外からのアクセスも有効にするにチェックマークを入れることで解決しました。
アドバイス頂きました皆様、ありがとうございました。

投稿2021/12/22 17:40

退会済みユーザー

退会済みユーザー

総合スコア0

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

0

SSLを使っている場合は、明示的にssl設定も必要なはずです。

PHP

1 $mailer->SMTPSecure = 'ssl'; 2 $mailer->Port = 465;

このページを参考にしてみて、何が足りないか確認してみてください。
↓stack overflow内の質問と回答
Mailer Error: SMTP connect() failed in php mailer( https://github.com/PHPMailer/PHPMailer/wiki/Troubleshooting) [duplicate]

投稿2021/12/22 08:02

FKM

総合スコア3644

バッドをするには、ログインかつ

こちらの条件を満たす必要があります。

あなたの回答

tips

太字

斜体

打ち消し線

見出し

引用テキストの挿入

コードの挿入

リンクの挿入

リストの挿入

番号リストの挿入

表の挿入

水平線の挿入

プレビュー

15分調べてもわからないことは
teratailで質問しよう!

ただいまの回答率
85.47%

質問をまとめることで
思考を整理して素早く解決

テンプレート機能で
簡単に質問をまとめる

質問する

関連した質問