Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/273.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 接收电子邮件时出现问题_Php_Email - Fatal编程技术网

Php 接收电子邮件时出现问题

Php 接收电子邮件时出现问题,php,email,Php,Email,函数socketmail($to、$subject、$message、$headers、$debug=0) 如果我用continue更改break,它会工作,但我希望在未发送电子邮件时发出警告。如果我测试此错误,消息是:Failure:553对不起,该域不在我允许的rcpthosts列表(#5.7.1)中 你能帮我吗?谢谢 553错误发生在您的邮件服务器被限制为开放中继时(这是一件好事,或者您可以为internet上的任何人转发任何电子邮件)。通常,当您使用mail()时,您使用的是本地服务器的

函数socketmail($to、$subject、$message、$headers、$debug=0)

如果我用continue更改break,它会工作,但我希望在未发送电子邮件时发出警告。如果我测试此错误,消息是:Failure:553对不起,该域不在我允许的rcpthosts列表(#5.7.1)中


你能帮我吗?谢谢

553错误发生在您的邮件服务器被限制为开放中继时(这是一件好事,或者您可以为internet上的任何人转发任何电子邮件)。通常,当您使用mail()时,您使用的是本地服务器的MTA(如果这是Linux,则为sendmail)。因此,您的远程服务器无法用于以这种方式发送您的电子邮件。或者您需要联系远程服务器,并将此脚本运行的服务器列入白名单(首选),或者允许您尝试在中继中发送到的域(这可能允许任何人中继到这些域)

出于好奇,为什么不使用mail()?这比打开原始套接字要简单得多

{global $MAILFROM;
$from=$MAILFROM;
 list($me,$mydomain) = split("@",$from);

// Now look up the mail exchangers for the recipient
 list($user,$domain) = split("@",$from,2);
 if(getmxrr($domain,$mx,$weight) == 0)  return FALSE;

// Try them in order of lowest weight first
array_multisort($mx,$weight);
$success=0;
    foreach($mx as $host) 
{
    // Open an SMTP connection
    //echo "$host To: $to<HR>";
    //print "SMTP: $host\n";

    $connection = fsockopen ($host, 25, &$errno, &$errstr, 1);
    if (!$connection)
        continue;
    $res=fgets($connection,256);
    if(substr($res,0,3) != "220") break;

    // Introduce ourselves
    fputs($connection, "HELO $mydomain\n");
    $res=fgets($connection,256);
    if(substr($res,0,3) != "250") break;

    // Envelope from
    fputs($connection, "MAIL FROM: $from\n");
    $res=fgets($connection,256);
    if(substr($res,0,3) != "250") break;

    // Envelope to
    fputs($connection, "RCPT TO: $to\n");
    $res=fgets($connection,256);
    //print "Response: $res\n";
    if(substr($res,0,3) != "250") break;

    // The message
    fputs($connection, "DATA\n");
    $res=fgets($connection,256);
    if(substr($res,0,3) != "354") break;

    // Send To:, From:, Subject:, other headers, blank line, message, and finish
    // with a period on its own line.
    fputs($connection, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
    $res=fgets($connection,256);
    if(substr($res,0,3) != "250") break;

    // Say bye bye
    fputs($connection,"QUIT\n");
    $res=fgets($connection,256);
    if(substr($res,0,3) != "221") break;

    // It worked! So break out of the loop which tries all the mail exchangers.
    $success=1;
    break;
}

 // Debug for if we fall over - uncomment as desired
if($debug) 
{
    print $success?"Mail sent":"Failure: $res\n";
    die(0);
}
if($connection) 
{
    if($success==0) 
        fputs($connection, "QUIT\n");
    fclose ($connection);
}
return $success?TRUE:FALSE;
fputs($connection, "RCPT TO: $to\n");
$res=fgets($connection,256);
//print "Response: $res\n";
if(substr($res,0,3) != "250") break;