PHP code example of okutani-t / nphpmailer
1. Go to this page and download the library: Download okutani-t/nphpmailer library . Choose the download type require .
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
okutani-t / nphpmailer example snippets
use OkutaniT\NPHPMailer;
NPHPMailer::_()
#->setSMTP(ホスト, ユーザー, パスワード) // サーバーで設定していたら不要
->setFrom(差出人)
->addAddress(宛先)
->setSubject(件名)
->setBody(内容)
->send();
use OkutaniT\NPHPMailer;
$from = "[email protected] ";
$to = [
"[email protected] "
];
$reply = $_POST["email"];
$mySubject = "お問い合わせがありました";
$myBody = "名前: " . $_POST["name"] . "\n" .
"メールアドレス: " . $_POST["email"];
$toSubject = "[自動返信]お問い合わせありがとうございます";
$toBody = "以下の内容でメールを送信しました。\n\n" .
"名前: " . $_POST["name"] . "\n" .
"メールアドレス: " . $_POST["email"] . "\n" .
"今後ともよろしくお願いいたします。";
// 自分宛
NPHPMailer::_()
->setSMTP("smtp.gmail.com", "〇〇@gmail.com", "Gmailのパスワード") # gmailの場合
->setFrom($from)
->addAddress($to)
->setSubject($mySubject)
->setBody($myBody)
->send();
// 相手宛(自動返信用)
NPHPMailer::_()
->setSMTP("smtp.gmail.com", "〇〇@gmail.com", "Gmailのパスワード")
->setFrom($from)
->addAddress($reply)
->setSubject($toSubject)
->setBody($toBody)
->send();
kutaniT\NPHPMailer;
// code...