php - 如何在 localhost/xampp 服务器上发送电子邮件?
问题描述
我正在尝试使用我的otp.php
文件在 localhost 上发送电子邮件,但我不知道如何在 localhost 上发送电子邮件。
这是我的文件:
<?php
$otp = rand(100000, 999999);
if (isset($_POST['submit'])) {
$to = $_POST['email'];
$from = "garvs0109@gmail.com";
$message = "
<!DOCTYPE html>
<html>
<body>
<h1>Your verification code is $otp</h1>
</body>
</html>";
$headers = "MIME-VERSION: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";
$result = mail($to,$subject,$message,$headers);
if (!$result) {
echo "<p><b>Error sending mail</b></p><br><br>";
} else {
echo "<p><b>Mail sent successfully</b></p><br><br>";
}
}
?>
谁能帮我处理这段代码,我应该在代码中添加什么?
解决方案
推荐阅读
- azure - 通过 Powershell 添加负载均衡器规则
- matlab - 在一张图中绘制多个神经网络径向基函数?
- jquery - 使用 jquery 和 scss 的自定义按钮动画无法停止
- angular - 如何在角度使用ngFor同时迭代两个数组?
- react-native - 无法使用 React native 发出 post 请求
- xquery - 如何有效地替换 XML 的多个节点?
- mysql - 如果准备好的语句查询不存在行,则返回一些东西
- android - DreamService 的屏幕保护程序
- php - 使用元素数组 [[["5"]]] 在 php 中创建 if-else 条件状态
- java - 修改 camera2 策略 - 无法获取 cameradevice