dpge74512 2014-08-19 11:11
浏览 21
已采纳

PHP mail()不会发送到某些帐户

I’m having problems with mailing. I have this code:

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

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

$mensaje = "Este mensaje fue enviado por " . $nombre . ", con dni " . $dni . " 
";
$mensaje .= "Su e-mail es: " . $email . " 
";
$mensaje .= "Mensaje: mensaje de prueba 
";
$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';
?> 

This script print “Mensaje enviado correctamente” in the screen, and it sends well to Gmail account, and innova.com account, but the mail doesn’t arrive to educacion.net account.

  • 写回答

1条回答 默认 最新

  • doujiu8145 2014-08-19 12:34
    关注

    Some email/domains have blocked PHP form emails, I'm surprised Gmail is working, usually you have to apply to be able to receive PHP forms.

    You'll need to add your smtpServer connection and call in this function when you want to be able to send PHP emails to whomever you need.

    <?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 = "
    ";           // 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
    From: $from
    Subject: $subject
    $headers
    
    $message
    .
    ");
    $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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥17 pro*C预编译“闪回查询”报错SCN不能识别
  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向