如何在 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>";
    }
}
?>

谁能帮我写这段代码,我应该在代码添加什么?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)