从localhost将gmail发送到admin的gmail

时间:2018-05-20 18:17:13

标签: php

我想从localhost发送邮件到我的gmail帐户。我在php.ini和sendmail.ini中设置了使用smtp服务器的所有设置。当我发送数据时,一切正常,但我没有收到任何传入消息。我怎么能这样做?请帮助我。

这是我的代码mail.php

<form method="post" action="sendmail.php">
    Email address:
    <input name="email" type="text" />
    <br /> Name:
    <input name="name" type="text" />
    <br /> Message:
    <br />
    <textarea name="message" rows="15" cols="40"></textarea>
    <br />
    <input type="submit" />
</form>

这里是sendmail.php

<?php
    echo 'Current PHP version: ' . phpversion();
    $email_to = "khinthidaphyo92@gmail.com";
    $name = $_POST["name"];
    $email_from = $_POST["email"];
    $message = $_POST["message"];
    $email_subject = "Feedback from website";
    $headers = "From: " . $email_from . "\n";
    $headers .= "Reply-To: " . $email_from . "\n";
    $message = "Name: ". $name . "\r\nMessage: " . $message;
    ini_set("sendmail_from", $email_from);
    $sent = mail($email_to, $email_subject, $message, $headers, "-f" .$email_from);
    echo $sent;
    echo "sent mail is" .$sent;
    if ($sent)
    {
        echo "It has been sent";
    } else {
        echo "There has been an error sending your comments. Please try later.";
    }
?>

2 个答案:

答案 0 :(得分:0)

你的系统是什么?视窗?使用sendmail for windows

答案 1 :(得分:0)

如果您使用本地主机直接发送电子邮件,则邮件可能最终会出现在Google的垃圾邮件过滤器中。最简单的选择是仅使用本地邮件程序将电子邮件转发到gmail服务器,然后进行实际邮件发送。这样谷歌就不会将你视为垃圾邮件发送者。

有一篇文章是关于https://linuxconfig.org/configuring-gmail-as-sendmail-email-relay如何将Gmail配置为Sendmail电子邮件中继的。

更容易使用您的互联网服务提供商smtp服务器,它通常甚至在从网络连接时都不需要身份验证。

相关问题