PHP mail()不’;I don’我不能发送到某些帐户

PHP mail()不’;I don’我不能发送到某些帐户,php,email,Php,Email,我在邮寄方面有问题。我有以下代码: <?php $dni = "123456"; $nombre = "dani"; $email = "abcd@gmail.com"; $header = 'De: ' . $email . " \r\n"; $header .= "X-Mailer: PHP/" . phpversion() . " \r\n"; $header .= "Mime-Version: 1.0 \r\n"; $header .= "Content-Type: text/p

我在邮寄方面有问题。我有以下代码:

<?php
$dni = "123456";
$nombre = "dani";
$email = "abcd@gmail.com";

$header = 'De: ' . $email . " \r\n";
$header .= "X-Mailer: PHP/" . phpversion() . " \r\n";
$header .= "Mime-Version: 1.0 \r\n";
$header .= "Content-Type: text/plain";

$mensaje = "Este mensaje fue enviado por " . $nombre . ", con dni " . $dni . " \r\n";
$mensaje .= "Su e-mail es: " . $email . " \r\n";
$mensaje .= "Mensaje: mensaje de prueba \r\n";
$mensaje .= "Enviado el " . date('d/m/Y', time());

$para = '1234@gmail.com,1234@innova.com,1234@educacion.net';
$asunto = '[Mensaje de Web]';

if (mail($para, $asunto, $mensaje, $header))
    echo 'Mensaje enviado correctamente';
else
    echo 'Error en el envio';
?> 


这个脚本在屏幕上打印“Mensaje enviado correctamente”,它很好地发送到Gmail帐户和innova.com帐户,但邮件没有到达educacion.net帐户。

一些电子邮件/域阻止了PHP表单电子邮件,我很惊讶Gmail能够正常工作,通常你必须申请才能接收PHP表单

当您希望能够向任何需要的人发送PHP电子邮件时,需要添加smtpServer连接并调用此函数

<?php 

function authgMail($from, $namefrom, $to, $nameto, $subject, $message) {

$smtpServer = "mail.domain.com";   //ip address of the mail server.  This can also be the local domain name
$port = "25";                    // should be 25 by default, but needs to be whichever port the mail server will be using for smtp
$timeout = "45";                 // typical timeout. try 45 for slow servers
$username = "yourusername"; // the login for your smtp
$password = "yourpassword";         // the password for your smtp
$localhost = "localhost";      // Defined for the web server.  Since this is where we are gathering the details for the email
$newLine = "\r\n";           // aka, carrage return line feed. var just for newlines in MS
$secure = 0;                  // change to 1 if your server is running under SSL

//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect)) {
    $output = "Failed to connect: $smtpResponse";
    echo $output;
    return $output;
}
else {
    //$logArray['connection'] = "<p>Connected to: $smtpResponse";
    //echo "<p />connection accepted<br>".$smtpResponse."<p />Continuing<p />";
}

//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";

//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";

//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";

//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";

//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";

//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";

//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

//observe the . after the newline, it signals the end of message
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data2response'] = "$smtpResponse";

// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
return($logArray);
}

可能是您的服务器IP被列入黑名单。可能是输入错误:
教育.net
对不起,我不明白您好@NicoleScotsburn,这样行。在我的例子中,我使用的是wordpress,所以我安装了一个插件,允许您使用smtp服务器配置邮件。所以,我强迫wordpress通过smtp服务器发送所有邮件,并添加了我的smtp凭据。现在,一切正常。Php mail()函数在这种情况下不起作用,因为我的网站和Web服务在同一台机器上,而邮件帐户在另一台机器上。非常感谢