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 Mapreduce是正常的,在运行其他jar包时并没有任何问题,只是在做LogCount.jar 时出的问题。如图所示
  • ¥15 ImportError: DLL load failed while importing _iterative: 找不到指定的模块。
  • ¥15 如何通过交互分析得出某高危患者对放疗获益更多
  • ¥15 相关性分析中,p<0.05, r=0.29,怎么评价相关性呢
  • ¥15 docker部署Mongodb后输入命令报错?
  • ¥15 将下列流程图转变成python程序代码
  • ¥15 我需要全国每个城市的最新小区名字等数据。
  • ¥15 开发一个小区生态的小程序
  • ¥15 如何解决Excel中dependent dropdown list 的问题
  • ¥15 MddBootstrapInitialize2失败