Ver Mensaje Individual
  #1 (permalink)  
Antiguo 19/03/2011, 12:34
Avatar de guichogdl
guichogdl
 
Fecha de Ingreso: abril-2010
Ubicación: gdl
Mensajes: 131
Antigüedad: 14 años, 11 meses
Puntos: 1
Pregunta envio de email por SMTP

hola a todos, estoy intentando implementar en un sitio web montado en un hosting gratuito (byethost) el enviar un email de bienvenida al que se registre por medio de gmail.
Encontre una funcion para enviarlo por SMTP pero no eh podido configurar la parte del Servidor de Email, la cual es esta:

Código PHP:
$smtpServer ‘www.tuservidordemail.com’;
$port ‘25′;
$timeout ‘60′;
$username ‘tunombreusuario’;
$password ‘tupassword’;
$localhost ‘www.tudominio.com’;
$newLine “rn”
yo la edite quedando de esta forma pero sin lograr que funcionara :S

Código PHP:
    $smtpServer  'ssl://smtp.googlemail.com'
    
$port        '465';
    
$timeout     '60';
    
$username    '[email protected]';
    
$password    'contrasena123456';
    
$localhost   'sql201.byethost52.com'
    
$newLine     "\r\n"
investige que gmail usa el puerto 465 por eso lo cambie, pero ni con ese ni con el 25 logre que se enviara el correo, espero pudieras decirme en que me equivoque y como podria solucionarlo.
Dejo la funcion completa como la encontre en la red por si no me di a entender bien XD

Código PHP:
/**
 * Esta funcion permite enviar un email en formato:
 * texto o html por protocolo SMTP.
 *
 * Auto: Edwin Sandoval < contacto [at] perfilgeek.com >
 *
 * @param String $format
 * @return boolean
 */
 
function mailporsmtp$mail_from    '',
                    
$mail_to      '',
                    
$mail_cc      '',
                    
$mail_bcc     '',
                    
$mail_subject '',
                    
$mail_data    '',
                    
$mail_format  'text' ){
 
    
$smtpServer  'www.tuservidordemail.com';
    
$port        '25';
    
$timeout     '60';
    
$username    'tunombreusuario';
    
$password    'tupassword';
    
$localhost   'www.tudominio.com';
    
$newLine     "\r\n";
 
    
$conexionsmtp fsockopen$smtpServer$port$errno$errstr$timeout );
 
    
fputs$conexionsmtp,' AUTH LOGIN'.$newLine );
    
fputs$conexionsmtp,  base64_encode$username ) . $newLine   );
    
fputs$conexionsmtp,  base64_encode$password ) . $newLine   );
    
fputs$conexionsmtp'HELO '       $localhost  $newLine    );
    
fputs$conexionsmtp'MAIL FROM: ' $mail_from  $newLine    );
    
fputs$conexionsmtp'RCPT TO: '   $mail_to    $newLine    );
 
    if( !empty( 
$mail_cc ) ){
        
fputs$conexionsmtp'RCPT TO: '   $mail_cc   $newLine    );
    }
 
    if( !empty( 
$mail_bcc ) ){
        
fputs$conexionsmtp'RCPT TO: '   $mail_bcc  $newLine    );
    }
 
    
fputs$conexionsmtp'DATA'            $newLine                  );
 
    
fflush$conexionsmtp );
 
    
$raw  "";
    
$raw  = @fread$conexionsmtp255 );
    
$raw .= @fread$conexionsmtp255 );
 
    
fputs$conexionsmtp'To:     '  $mail_to        $newLine );
    
fputs$conexionsmtp'From:   <' $mail_from .'>' $newLine );
    
fputs$conexionsmtp'Subject:'  $mail_subject   $newLine );
 
    if( 
$mail_format == 'text' ){
 
        
$headers  "Content-Type: text/plain; charset=\"iso-8859-1\"" "\r\n";
        
$headers .= "Content-Transfer-Encoding: 7bit" "\r\n";
 
        
$message  $mail_data;
 
        
fputs$conexionsmtp$headers   $newLine  $newLine       );
        
fputs$conexionsmtp$message   $newLine  '.' $newLine );
 
    }else{
 
        
$random_hash md5(date('r'time()));
 
        
$headers  "Content-Type: multipart/alternative; boundary=\"PHP-alt-".$random_hash."\"\r\n";
        
$headers .= "--PHP-alt-" $random_hash "\r\n";
        
$headers .= "Content-Type: text/plain; charset=\"iso-8859-1\"" "\r\n";
        
$headers .= "Content-Transfer-Encoding: 7bit" "\r\n";
 
        
$message  $mail_data[0];
 
        
fputs$conexionsmtp$headers $newLine );
        
fputs$conexionsmtp$message $newLine );
 
        
$headers  "--PHP-alt-" $random_hash "\r\n";
        
$headers .= "Content-Type: text/html; charset=\"iso-8859-1\"" "\r\n";
        
$headers .= "Content-Transfer-Encoding: 7bit" "\r\n";
 
        
$message  $mail_data[1];
 
        
fputs$conexionsmtp$headers  $newLine );
        
fputs$conexionsmtp$message  $newLine );
 
        
$headers  "--PHP-alt-" $random_hash "--\r\n";
 
        
fputs$conexionsmtp$headers '.' $newLine  );
 
    }
 
    
fputs$conexionsmtp,'QUIT' $newLine );
 
    return 
true;
 

Para operar esta función deberemos pasarle los siguientes parámetros:

Código PHP:
$mail_from    '' // Dirección de Correo Remitente
$mail_to      '' // Dirección de Correo Destinatario
$mail_cc      '' // Dirección de Correo Destinatario
$mail_bcc     '' // Dirección de Correo Destinatario
$mail_subject '' // Asunto del Mensaje
$mail_data    '' // Texto Plano o un Array ( $mail_data[0] = 'texto plano'; $mail_data[1] = '<p>html mail</p>'; )
$mail_format  'text' // Formato del Email ( text o html )