php mail功能无法连接到邮件服务器

时间:2018-06-01 06:25:09

标签: php email

我将使用php邮件功能发送邮件,但它可能会显示一些错误..

  

警告:mail():无法连接到邮件服务器        "本地主机"端口25,验证您的" SMTP"和        " SMTP_PORT"在php.ini中设置或在

中使用ini_set()

mail.php

    <?PHP
    $sender = 'sender123@gmail.com';
    $recipient = 'resever123@gmail.com';

    $subject = "php mail test";
    $message = "php test message";
    $headers = 'From:' . $sender;

    if (mail($recipient, $subject, $message, $headers))
    {
        echo "Message accepted";
    }
    else
    {
        echo "Error: Message not accepted";
    }
    ?>

1 个答案:

答案 0 :(得分:1)

如果您在本地主机上进行测试,则很可能没有SMTP设置。您必须为php设置smtp连接才能发送消息。

我建议使用像phpmailer这样的东西,这使得在本地测试服务器上工作变得更容易。