Ver Mensaje Individual
  #2 (permalink)  
Antiguo 24/02/2007, 09:22
ReFleXmza
 
Fecha de Ingreso: febrero-2007
Mensajes: 28
Antigüedad: 17 años, 2 meses
Puntos: 0
De acuerdo Re: Ayuda novato problemas con mail()

Hoy en dia casi el 100% de los servidores de SMTP necesitan autenticacion... esto significa que necesitas enviarles tu nombre de usuario y contraseña al servidor para enviar mail.. lamentablemente php no trae esta funcion incluida por lo que deberas usar una clase de envio de mails externa que permita authentication SMTP. A continuacion pego una funcion de envio de mails con autenticacion para que les sirva de ejemplo.
Código:
<?php
//new function

$to = "[email protected]";
$nameto = "Who To";
$from = "[email protected]";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!"
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */ 

//Authenticate Send - 21st March 2005
//This will send an email using auth smtp and output a log array
//logArray - connection, 

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
    //SMTP + SERVER DETAILS
    /* * * * CONFIGURATION START * * * */
    $smtpServer = "mail.server.com";
    $port = "25";
    $timeout = "30";
    $username = "smtpusername";
    $password = "smtppassword";
    $localhost = "localhost";
    $newLine = "\r\n";
    /* * * * CONFIGURATION END * * * * */
    
    //Connect to the host on the specified port
    $smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
    $smtpResponse = fgets($smtpConnect, 515);
    if(empty($smtpConnect)) 
    {
        $output = "Failed to connect: $smtpResponse";
        return $output;
    }
    else
    {
        $logArray['connection'] = "Connected: $smtpResponse";
    }

    //Request Auth Login
    fputs($smtpConnect,"AUTH LOGIN" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authrequest'] = "$smtpResponse";
    
    //Send username
    fputs($smtpConnect, base64_encode($username) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authusername'] = "$smtpResponse";
    
    //Send password
    fputs($smtpConnect, base64_encode($password) . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['authpassword'] = "$smtpResponse";

    //Say Hello to SMTP
    fputs($smtpConnect, "HELO $localhost" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['heloresponse'] = "$smtpResponse";
    
    //Email From
    fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailfromresponse'] = "$smtpResponse";
        
    //Email To
    fputs($smtpConnect, "RCPT TO: $to" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['mailtoresponse'] = "$smtpResponse";
    
    //The Email
    fputs($smtpConnect, "DATA" . $newLine);
    $smtpResponse = fgets($smtpConnect, 515);
    $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;
    
    fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['data2response'] = "$smtpResponse";
    
    // Say Bye to SMTP
    fputs($smtpConnect,"QUIT" . $newLine); 
    $smtpResponse = fgets($smtpConnect, 515);
    $logArray['quitresponse'] = "$smtpResponse";    
}
?>
Este codigo fue crado por bjpalmer

La otra solucion es instalar un SMTP RELAY SERVER en tu pc y hacer que tu maquina se convierta enun server de envio de mails sin necesita de autenticacion. Aqui les dejo el link para encontrar un SMTP REALY SERVER busquen en GOOGLE lo siguiente: "SMTP RELAY SERVER"+download .Traten de buscar uno gratis

Otra de las soluciones es modificar el archivo PEAR de envio de mail y agregar tu propia funcion... pero es bastante complicado y la verdad no lo he provado nunca

Espero que les sea de utilidad. SALUDOS!