You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

PHP配置SMTP使用mail函数发送邮件报错求助

PHP mail函数结合SMTP发送邮件报错排查求助

我尝试使用PHP的mail函数结合SMTP配置给自己发送邮件,但出现报错:
报错截图

我使用的代码如下:

function notify_password($username, $password) {
// notify the user that their password has been changed

    $conn = db_connect();
    $result = $conn->query("select email from user
                            where username='".$username."'");
    if (!$result) {
      throw new Exception('Could not find email address.');
    } else if ($result->num_rows == 0) {
      throw new Exception('Could not find email address.');
      // username not in db
    } else {
      $row = $result->fetch_object();
      $email = $row->email;
      $from = "From: di@gmail.com \r\n";
      $mesg = "Your  password has been changed to ".$password."\r\n"
              ."Please change it next time you log in.\r\n";

      if (mail($email, 'login information', $mesg, $from)) {
        return true;
      } else {
        throw new Exception('Could not send email.');
      }
    }
}

我的php.ini文件配置如下:
php.ini配置截图

sendmail文件配置如下:
sendmail配置截图

请帮忙排查问题。

内容的提问来源于stack exchange,提问作者Dimitris Lisg

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 10:55:07