CodeIgniter Forums
Email using SMTP....no good. - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Email using SMTP....no good. (/showthread.php?tid=60494)

Pages: 1 2


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]JackU[/eluser]
[UPDATE]
This issue is solved. I followed the docs on the Email class and left out 'clrf' and 'newline' and used the default....then i used it in all combos...using single quotes around the string. CroNiX suggested i use double quotes around the strings....and it works...and it is fast! Woaw...been coding PHP for years and have never run in to stuff like this (i use both single and double quotes). I guess i have been really lucky :-) Thanx CroNiX for the tip. Also a tip....don´t use single quotes like in the docs.
[/UDPATE]

I have been trying to send mail using the codeigniter Email class. But no luck. I´m not sure what i am doing wrong. Any help appreciated!

Code:
$this->load->library('email');
        $configs['smtp_timeout'] = 120;
        $configs['clrf'] = '\r\n';
        $configs['newline'] = '\r\n';
        $configs['protocol'] = 'smtp';
        $configs['smtp_host'] = 'smtp.test.se';
        $configs['smtp_user'] = 'myuser';
        $configs['smtp_pass'] = 'password';
        $configs['charset'] = 'iso-8859-1';
        //$configs['$send_multipart'] = FALSE;
        $this->email->initialize($configs);
        $this->email->from('[email protected]','test');
        $this->email->to('[email protected]');
        //$this->email->reply_to('[email protected]','test');
        $this->email->subject('Some subject');
        $this->email->message('Some message');        
        $this->email->send();
        echo $this->email->print_debugger();



It takes a loooooong while before anything happens and then i get this log:

220 smtp.test.net ESMTP IceWarp 11.0.0.2; Tue, 08 Apr 2014 14:42:28 +0200

hello: 250-smtp.test.net Hello www.mysite.se [xx.xxx.xxx.xx], pleased to meet you.
250-ENHANCEDSTATUSCODES
250-SIZE 41943040
250-EXPN
250-ETRN
250-ATRN
250-DSN
250-CHECKPOINT
250-8BITMIME
250-AUTH PLAIN LOGIN DIGEST-MD5 CRAM-MD5 GSSAPI
250-STARTTLS
250-VRFY
250 HELP

from: 250 2.1.0 ... Sender ok

to: 250 2.1.5 ... Recipient ok; will forward

data: 354 Enter mail, end with "." on a line by itself


The following SMTP error was encountered:
Unable to send email using PHP SMTP. Your server might not be configured to send mail using this method.

User-Agent: CodeIgniter
Date: Tue, 8 Apr 2014 14:42:27 +0200
From: "Test" <[email protected]>
Return-Path: <[email protected]>
To: [email protected]
Subject: =?iso-8859-1?Q?=4A=F2=72=65=20=6A=6C=2E=20=31=33=2A=32=32?=
Reply-To: "[email protected]" <[email protected]>
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <5342eeb350199@test>
Mime-Version: 1.0





Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]stevezissou[/eluser]
What port does your SMTP server run on? Add the 'smtp_port' value to your configuration.


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]JackU[/eluser]
[quote author="stevezissou" date="1396964845"]What port does your SMTP server run on? Add the 'smtp_port' value to your configuration.[/quote]

Adding the port to the config didn´t have any effect. It defaults to 25. And that is the correct port.

Don´t know what the SMTP server is running on.

Code on this page works for some reason:
http://www.dreamincode.net/forums/topic/36108-send-emails-using-php-smtp-direct/

Used this settings:
$smtpServer = "smtp.test.se"; //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 = "120"; // typical timeout. try 45 for slow servers
$username = "myusername "; // the login for your smtp
$password = "mypassword"; // the password for your smtp
$localhost = "127.0.0.1"; // 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;


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]stevezissou[/eluser]
Double check that port 25 is actually the port you need to send on. Try using CI's defaults for 'newline' and 'crlf'. Also, is there anything more in your logs after this line: "data: 354 Enter mail, end with “.” on a line by itself"?

CI returns your error message when it doesn't receive 250 in the response from the SMTP server.


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]stevezissou[/eluser]
Quote:It takes a loooooong while before anything happens

Also, regarding this...SMTP is going to be slow for a variety of reasons. If you plan on sending a lot of messages or have to support a lot of users, sending messages on the fly via SMTP is going to super slow without a proper queue/batch system in place. If you still are having a problem with slow response times from your SMTP server (after getting it working), I'd suggest you look into a service like Mandrill (http://mandrill.com/) and use their APIs (not their SMTP methods) for sending messages.


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]JackU[/eluser]
[quote author="stevezissou" date="1396971078"]Double check that port 25 is actually the port you need to send on. Try using CI's defaults for 'newline' and 'crlf'. Also, is there anything more in your logs after this line: "data: 354 Enter mail, end with “.” on a line by itself"?

CI returns your error message when it doesn't receive 250 in the response from the SMTP server.[/quote]

I use Telnet to talk to directly to SMTP server and the port 25 is the correct one. I have used all combos of 'newline' and 'crlf' because i though that that was the issue. But no go.

Whole log is posted in my original post. That is what i get from the print-debugger function in the email class.


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]JackU[/eluser]
[quote author="stevezissou" date="1396973062"]
Quote:It takes a loooooong while before anything happens

Also, regarding this...SMTP is going to be slow for a variety of reasons.[/quote]

There is no reason for it to be this slow. We talk about 60 + seconds before the response. I tried out coding it from the link above. And it works...instantly. No delays whatsoever.

I´m at a point right now that i may extend the Email class with a smtp_fix and use the code that i got to work (check post above). There seems to be something "wooonkey" with the SMTP code in the Email class. But i really don´t want to do that. I would like to use the CodeIgniter´s base classes.

If you have any other ideas pls post it.I appreciate you guys help!


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]ivantcholakov[/eluser]
@JackU

If you have no success yet, I would suggest you to make a wild try with a library of mine. It swaps the original CodeIgniter's mailer with PHPMailer, the API remains the same.

https://github.com/ivantcholakov/codeigniter-phpmailer

Currently I check it against CodeIgniter 3, anyway I think, it would still be working on CodeIgniter 2.x.

I don't understand the SMTP protocol deeply, actually I don't want to go there. The PHPMailer does the job for me well.


Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]InsiteFX[/eluser]
You also need to setup your SMTP in your PHP.ini file



Email using SMTP....no good. - El Forum - 04-08-2014

[eluser]CroNiX[/eluser]
Code:
$configs['clrf'] = '\r\n';
$configs['newline'] = '\r\n';

These shouldn't be in single quotes

I would also suggest using UTF-8 as the charset.