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 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器