2011-06-01 21 views
7

Hola, estoy tratando de enviar correos electrónicos usando la función de clase de correo codeiginiter, pero encontré un problema con el protocolo smtp. Estoy usando el protocolo smtp de gmail. Estoy ejecutando esto en una máquina local. estoy usando XAMPP 1.7.4 paquete, andI intentado fijar, como a continuación:cómo corregir la forma de enviar correos electrónicos usando codeigniter

function index() 
{ 

    $config['protocol'] = 'smtp'; // mail, sendmail, or smtp The mail sending protocol. 
    $config['smtp_host'] = 'smtp.gmail.com'; // SMTP Server Address. 
    $config['smtp_user'] = '[email protected]'; // SMTP Username. 
    $config['smtp_pass'] = '123'; // SMTP Password. 
    $config['smtp_port'] = '25'; // SMTP Port. 
    $config['smtp_timeout'] = '5'; // SMTP Timeout (in seconds). 
    $config['wordwrap'] = TRUE; // TRUE or FALSE (boolean) Enable word-wrap. 
    $config['wrapchars'] = 76; // Character count to wrap at. 
    $config['mailtype'] = 'html'; // text or html Type of mail. If you send HTML email you must send it as a complete web page. Make sure you don't have any relative links or relative image paths otherwise they will not work. 
    $config['charset'] = 'utf-8'; // Character set (utf-8, iso-8859-1, etc.). 
    $config['validate'] = FALSE; // TRUE or FALSE (boolean) Whether to validate the email address. 
    $config['priority'] = 3; // 1, 2, 3, 4, 5 Email Priority. 1 = highest. 5 = lowest. 3 = normal. 
    $config['crlf'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
    $config['newline'] = "\r\n"; // "\r\n" or "\n" or "\r" Newline character. (Use "\r\n" to comply with RFC 822). 
    $config['bcc_batch_mode'] = FALSE; // TRUE or FALSE (boolean) Enable BCC Batch Mode. 
    $config['bcc_batch_size'] = 200; // Number of emails in each BCC batch. 

    $this->load->library('email'); 
    $this->email->initialize($config); 


    $this->email->from('[email protected]', 'Me'); 
    $this->email->reply_to('[email protected]', 'Me'); 
    $this->email->to('[email protected]'); 
    $this->email->subject('testing my mail function with CodeIgniter'); 
    $this->email->message('<html><body>this is the content</body></html>'); 

    if (! $this->email->send()){ 
     echo 'error! <br />'; 
     // Generate error 
    } 
    echo $this->email->print_debugger(); 

} 

y por debajo de error era espectáculo en mi navegador:

error! 
220 mx.google.com ESMTP b8sm581192pbj.46 

hello: 250-mx.google.com at your service, [118.96.231.25] 
250-SIZE 35882577 
250-8BITMIME 
250-STARTTLS 
250 ENHANCEDSTATUSCODES 

Failed to send AUTH LOGIN command. Error: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

from: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

to: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

data: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 

The following SMTP error was encountered: 530 5.7.0 Must issue a STARTTLS command first. b8sm581192pbj.46 
502 5.5.1 Unrecognized command. b8sm581192pbj.46 
The following SMTP error was encountered: 502 5.5.1 Unrecognized command. b8sm581192pbj.46 
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method. 

User-Agent: CodeIgniter 
Date: Wed, 1 Jun 2011 09:27:21 +0700 
From: "Me" 
Return-Path: 
Reply-To: "Me" 
To: [email protected] 
Subject: =?utf-8?Q?testing_my_mail_function_with_CodeIgniter?= 
X-Sender: [email protected] 
X-Mailer: CodeIgniter 
X-Priority: 3 (Normal) 
Message-ID: <[email protected]> 
Mime-Version: 1.0 


Content-Type: multipart/alternative; boundary="B_ALT_4de5a38938733" 

This is a multi-part message in MIME format. 
Your email application may not support this format. 

--B_ALT_4de5a38938733 
Content-Type: text/plain; charset=utf-8 
Content-Transfer-Encoding: 8bit 

this is the content 


--B_ALT_4de5a38938733 
Content-Type: text/html; charset=utf-8 
Content-Transfer-Encoding: quoted-printable 

<html><body>this is the content</body></html> 

--B_ALT_4de5a38938733-- 

Respuesta

3

Está intentando enviar correo saliente a través de Gmail en el puerto SMTP estándar 25. Gmail no acepta conexiones no encriptadas en ese puerto (o cualquier puerto). Debe usar el puerto 465 sobre SSL.

Debe cambiar su $config['smtp_port'] a 465 y su $config['smtp_host'] a 'ssl://smtp.googlemail.com'

More info here

+1

su clave segunda matriz debe smtp_host – willoller

9

Por razones de seguridad, servidores de correo electrónico de Google require SSL or TLS con el fin de enviar correo. No utiliza el método estándar de puerto 25 no cifrado para hacerlo.

Básicamente tiene dos opciones. 1) Use sendmail o correo en su propio servidor para entregar los mensajes, o 2) use el método described here para enviar correos electrónicos a través de los servidores de Google utilizando SSL. Buena suerte, y espero que esto ayude.

+0

Si opta por utilizar sendmail en XAMPP, a continuación, recuerde que debe dejar de lado la parte del protocolo del servidor SMTP para que usted termina con smtp_server = smtp.googlemail.com – KalenGi

3

Usted puede incluso utilizar el puerto 587:

$config['smtp_port'] = '587'; 

y SMTP-host como:

$config['smtp_host'] = 'ssl://smtp.gmail.com'; 
+0

SOLO LLEVA A ' fsockopen(): SSL: una conexión existente fue cerrada a la fuerza por el host remoto. – SpYk3HH

-1

1) Usted puerto SMTP debe estar 465.

2) Usted smtp host debe ser ssl://smtp.gmail.com.

$config['smtp_host'] = 'ssl://smtp.gmail.com'; // SMTP Server Address. 

$config['smtp_port'] = '465'; // SMTP Port. 
1

I resuelto este problema mediante la inclusión de la ssl prefijo en smtp_host dejando de esta manera:

$config['smtp_host'] = 'ssl://smtp.gmail.com'; 

Y asegúrese de utilizar el puerto 465 (que es el puerto SMTP de Google):

$config['smtp_port'] = '465'; 

De lo contrario, de forma predeterminada, google bloquea las 'conexiones de baja seguridad', por lo que c Ingrese a su cuenta de google y configure esta opción.

Allow less secure apps to access accounts

activar esta opción y vuelva a intentarlo. ¡Espero que esto le pueda ayudar!.

Cuestiones relacionadas