【问题标题】:issues while sending email with xampp on localhost在本地主机上使用 xampp 发送电子邮件时出现问题
【发布时间】:2021-11-20 10:39:03
【问题描述】:

我正在处理一个需要发送电子邮件的项目。我的发送邮件功能是:

    ini_set('sendmail_path', "\"C:\xampp\sendmail\sendmail.exe\" -t");
    ini_set('smtp_server', 'smtp.gmail.com');
    ini_set('smtp_port', 25);
    ini_set('smtp_ssl', 'auto');
    ini_set('error_logfile', 'error.log');
    ini_set('auth_username', 'myemailAddreds@gmail.com');
    ini_set('auth_password', 'mygmail_password');

    //sendmail_from('myemailAddreds@gmail.com');

    $to = 'myemailAddreds@gmail.com';
    $subject = 'Hello from XAMPP!';
    $message = 'This is a test';
    $headers = "From: your@email-address.com\r\n";
    if (mail($to, $subject, $message, $headers)) {
       echo "SUCCESS";
    } else {
       echo "ERROR";
    }

但我收到以下错误

警告:mail():无法在“localhost”端口 25 连接到邮件服务器,请验证 php.ini 中的“SMTP”和“smtp_port”设置或在 C:\umtab\xampp 中使用 ini_set() \htdocs\umtab\email.php 第 23 行

【问题讨论】:

  • 使用 PHPMailer 比直接从 PHP 连接到 SMTP 服务器要好得多,而不是在 sendmail 设置中添加一层复杂性
  • 请告诉我们我们的解决方案是否适合您!

标签: php xampp


【解决方案1】:

从错误中可以看出:无法在“localhost”端口 25 连接到邮件服务器。写成localhost,好像服务器设置不正确。

我认为ini_set('smtp_server', 'smtp.gmail.com'); 不起作用。

尝试改用ini_set('SMTP','smtp.gmail.com'); ...这应该是设置SMTP服务器的正确方法!

但无论如何,正如@ADyson 所建议的,使用 PHPMailer 会更好。您可以阅读文档和用法right here

安德烈亚

【讨论】:

  • 好的,谢谢,我已经试过了,但我还是得到了这个错误 //Warning: mail(): SMTP server response: 530 5.7.0 Must issue a STARTTLS command first. l7sm1379142qtr.87 - gsmtp in C:\umtab\xampp\htdocs\umtab\email.php on line 24
  • 我会尝试使用 PHPMailer
  • 我建议你看看this post here ...它解释了如何弄清楚。如果我的回答对您有帮助,请将其标记为解决方案:)
  • 我会尽快尝试,感谢您的帮助
  • 您好,您的问题解决了吗?如果是,请将我的答案标记为解决方案!
猜你喜欢
  • 2015-08-07
  • 1970-01-01
  • 1970-01-01
  • 2013-10-01
  • 2010-12-19
  • 2013-12-18
  • 1970-01-01
  • 1970-01-01
  • 2019-08-05
相关资源
最近更新 更多