你可以通过以下命令使用Composer安装PHPMailer:
<span class="fun">composer require 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、发件人邮箱与密码等信息替换为你自己的实际配置。