【问题标题】:Unable to send mail from gmail with xampp (using php script)无法使用 xampp 从 gmail 发送邮件(使用 php 脚本)
【发布时间】:2014-04-17 21:40:44
【问题描述】:

我在 Windows 7 上使用 XAMPP,但无法使用 php 发送邮件

php.ini 文件部分如下:

SMTP = smtp.gmail.com
smtp_port = 25
sendmail_from = hima***ivast***@gmail.com
sendmail_path = "C:\xampp\sendmail\sendmail.exe -t"
mail.add_x_header = Off

sendmail.ini 文件部分如下:

smtp_server=smtp.gmail.com
smtp_port=25
error_logfile=error.log
debug_logfile=debug.log
auth_username=hima***ivast***@gmail.com
auth_password=************
force_sender=hima***ivast***@gmail.com

请帮我找出错误。

【问题讨论】:

    标签: php email windows-7 xampp sendmail.exe


    【解决方案1】:

    如果您在 Gmail 帐户上启用了 SSL,则端口号为 587。我相信另一个是 465,根据帮助文档:https://support.google.com/mail/answer/78775?hl=en

    如果您尝试在端口 465(使用 SSL)上配置 SMTP 服务器并且 端口 587(使用 TLS),但仍然无法发送邮件,请尝试 将您的 SMTP 配置为使用端口 25(使用 SSL)。

    您可能还应该使用 try/catch 块 - 如果 sendmail 因错误而失败,您可以 print_r 或 var_dump 查看异常消息包含的内容。

    我应该承认我从未直接使用过 sendmail;我发现 Rmail 库更容易使用:

    <?php
        require_once( ROOT . DS . "libs" . DS . "Rmail" . DS . "Rmail.php" );
    
        // Instantiate a new HTML Mime Mail object
        $mail = new Rmail();
    
        $mail->setSMTPParams($host = 'smtp.gmail.com', $port = 587, $helo = null, $auth = true, $user = 'gmail address', $pass = 'password');
    
        // Set the From and Reply-To headers
        $mail->setFrom( "Proper Name <send from email address>" );
        $mail->setReturnPath( "reply email address" );
    
        // Set the Subject
        $mail->setSubject( 'Email subject/title' );
    
        $html = 'you email message content';
    
        // Create the HTML e-mail
        $mail->setHTML( $html );
    
        // Send the e-mail
        $result = $mail->send( array( 'target email address' ) );
    ?>
    

    如果您更愿意使用上面的 sn-p 之类的东西,我可以在某个地方找到该库。

    【讨论】:

    • 三个端口都给出相同的结果。
    • 您是否确认可以使用您使用的凭据登录?
    • 是的,我可以使用凭据登录。我的代码有错误吗?
    猜你喜欢
    • 2014-07-29
    • 2013-07-13
    • 2011-11-30
    • 2021-01-27
    • 1970-01-01
    • 2012-02-18
    • 1970-01-01
    • 1970-01-01
    • 2015-10-26
    相关资源
    最近更新 更多