doudi4621 2014-03-17 05:58 采纳率: 0%
浏览 80
已采纳

我的邮件功能有什么问题?

I took a mail function from the open source punbb forum software.

Here it is:

function smtp_mail($to, $subject, $message, $headers, $username, $password, $host, $use_ssl){
    global $forum_config;

    $recipients = explode(',', $to);

    // Sanitize the message
    $message = str_replace("
.", "
..", $message);
    $message = (substr($message, 0, 1) == '.' ? '.'.$message : $message);

    // Are we using port 25 or a custom port?
    if (strpos($host, ':') !== false){
        list($smtp_host, $smtp_port) = explode(':', $host);
    }else{
        $smtp_host = $host;
        $smtp_port = 25;
    }

    if ($use_ssl == '1'){
        $smtp_host = 'ssl://'.$smtp_host;
    }

    if (!($socket = fsockopen($smtp_host, $smtp_port, $errno, $errstr, 15))){
        error('Could not connect to smtp host "'.$host.'" ('.$errno.') ('.$errstr.').', __FILE__, __LINE__);
    }

    server_parse($socket, '220');

    if ($username != '' && $password != ''){
        fwrite($socket, 'EHLO '.$smtp_host."
");
        server_parse($socket, '250');

        fwrite($socket, 'AUTH LOGIN'."
");
        server_parse($socket, '334');

        fwrite($socket, base64_encode($username)."
");
        server_parse($socket, '334');

        fwrite($socket, base64_encode($password)."
");
        server_parse($socket, '235');
    }else{
        fwrite($socket, 'HELO '.$smtp_host."
");
        server_parse($socket, '250');
    }

    fwrite($socket, 'MAIL FROM: <'.$username.'>'."
");
    server_parse($socket, '250');

    foreach ($recipients as $email){
        fwrite($socket, 'RCPT TO: <'.$email.'>'."
");
        server_parse($socket, '250');
    }

    fwrite($socket, 'DATA'."
");
    server_parse($socket, '354');

    fwrite($socket, 'Subject: '.$subject."
".'To: <'.implode('>, <', $recipients).'>'."
".$headers."

".$message."
");

    fwrite($socket, '.'."
");
    server_parse($socket, '250');

    fwrite($socket, 'QUIT'."
");
    fclose($socket);

    return true;
}

function server_parse($socket, $expected_response){
    $server_response = '';

    while (substr($server_response, 3, 1) != ' '){
        if (!($server_response = fgets($socket, 256))){
            error('Couldn\'t get mail server response codes.<br />Please contact the forum administrator.', __FILE__, __LINE__);
        }
    }

    if (!(substr($server_response, 0, 3) == $expected_response)){
        error('Unable to send e-mail.<br />Please contact the forum administrator with the following error message reported by the SMTP server: "'.$server_response.'"', __FILE__, __LINE__);
    }
}

function error($m){
    die($m);
}   

It works most of the time, but when sending to any gmail addresses the mail bounces with the following error code (modifications removing ip addresses, email addresses, etc):

This message was created automatically by mail delivery software.

A message that you sent could not be delivered to one or more of its
recipients. This is a permanent error. The following address(es) failed:

  someone@gmail.com
    SMTP error from remote mail server after end of data:
    host gmail-smtp-in.l.google.com [173.194.64.26]:
    550-5.7.1 [1.1.1.1      11] Our system has detected that this message is
    550-5.7.1 not RFC 2822 compliant. To reduce the amount of spam sent to Gmail,
    550-5.7.1 this message has been blocked. Please review
    550 5.7.1 RFC 2822 specifications for more information. sm4si11387798obb.202 - gsmtp

------ This is a copy of the message, including all the headers. ------

Return-path: <someone@terratekkit.org>
Received: from [1.1.1.1] (port=50336 helo=ssl://mail.example.com)
    by mail.example.com with esmtpsa (UNKNOWN:DHE-RSA-AES256-GCM-SHA384:256)
    (Exim 4.80.1)
    (envelope-from <someone@example.com>)
    id 1WPQMJ-0001mk-Q4
    for someone@gmail.com; Mon, 17 Mar 2014 00:45:11 -0500
Subject: test email
To: <someone@gmail.com>


this is a test

I do not know what the error is, I have attempted to look at the mentioned specification, but it is just a bunch of useless text that makes no sense to me :/.

  • 写回答

1条回答 默认 最新

  • duanhanglekr37902 2014-04-28 13:35
    关注

    try using http://phpmailer.worxware.com/ to sent smtp authentifacted emails which are accepted by gmail. Gmail is very unfriednly to spam look-a-like mails...

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 腾讯云如何建立同一个项目中物模型之间的联系
  • ¥30 VMware 云桌面水印如何添加
  • ¥15 用ns3仿真出5G核心网网元
  • ¥15 matlab答疑 关于海上风电的爬坡事件检测
  • ¥88 python部署量化回测异常问题
  • ¥30 酬劳2w元求合作写文章
  • ¥15 在现有系统基础上增加功能
  • ¥15 远程桌面文档内容复制粘贴,格式会变化
  • ¥15 这种微信登录授权 谁可以做啊
  • ¥15 请问我该如何添加自己的数据去运行蚁群算法代码