首页 > 解决方案 > 如何在 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>";
    }
}
?>

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

标签: phphtmlemailsmtpone-time-password

解决方案


推荐阅读