次のコマンドを介してComposerを使用してPHPMailerをインストールできます。
<span class="fun">Composerにはphpmailer/phpmailerが必要です</span>
<form action="sendmail.php" method="post">
<input type="text" name="name" placeholder="あなたの名前" required>
<input type="email" name="email" placeholder="あなたのメールアドレス" required>
<textarea name="message" placeholder="メッセージを入力してください" required></textarea>
<input type="submit" value="メールを送信します">
</form>
<?php
require 'PHPMailer/PHPMailerAutoload.php';
$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->Host = 'smtp.example.com'; // メールサーバー
$mail->SMTPAuth = true;
$mail->Username = 'your-email@example.com'; // 送信者のメール
$mail->Password = 'your-email-password'; // パスワードにメールしてください
$mail->SMTPSecure = 'tls';
$mail->Port = 587;
$mail->setFrom('your-email@example.com', 'Your Name');
$mail->addAddress('recipient@example.com'); // 受信者のメールアドレス
$mail->isHTML(true);
$mail->Subject = '新しいメールがあります';
$mail->Body = "名前:$name<br>郵便:$email<br>メッセージ:$message";
if(!$mail->send()) {
echo 'メールの送信に失敗しました:' . $mail->ErrorInfo;
} else {
echo '電子メールは正常に送信されました!';
}
?>
SMTP.example.com 、送信者の電子メールとパスワードを独自の実際の構成に置き換えてください。