• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending EMail From Code Igniter 2.0.1

#11
[eluser]Madmartigan1[/eluser]
Well I found out that the email class is not honoring my config settings, but that's a separate issue I'll have to look into.

[quote author="InsiteFX" date="1301796587"]You have to use the email classes smtp config! When I installed it defaulted to smtp port 25

When you start it, it will place an icon in the taskbar right click then options and it will tell you what your smtp port is!

InsiteFX[/quote]

InsiteFX, what did you have to configure on the CI end to get the Test Mail Server to work? CI Email and the test server both default to port 25, I tried "localhost" as the $smtp_host, and left the $smtp_user and $smtp_pass empty. I have no idea.

Quote:The following SMTP error was encountered: 10060 A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond.

The Mail server is running and I tried restarting apache. Any idea?

#12
[eluser]InsiteFX[/eluser]
I 'll write up a little demo and post it back here tomorrow!

You may beable to use the regular email stuff with out the smtp port 25 if I remember right!

InsiteFX

#13
[eluser]InsiteFX[/eluser]
Just test and this works so here is the code everyone, you will need to associate your email client for .eml files but it will show up in the mail server folder. I include a print_debugger in the view file which will show you the email!

Email.php - application/config/email.php
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|-------------------------------------------------------------------------
| Name: email.php
|-------------------------------------------------------------------------
|
|-------------------------------------------------------------------------
*/

$config['useragent']    = "CodeIgniter";    // The "user agent". ( None )
$config['protocol']        = "mail";            // The mail sending protocol. ( mail, sendmail, or smtp )
$config['mailpath']        = "";                // The server path to Sendmail. ( None )

$config['smtp_host']    = "";                // SMTP Server Address. ( None )
$config['smtp_user']    = "";                // SMTP Username. ( None )
$config['smtp_pass']    = "";                // SMTP Password. ( None )
$config['smtp_port']    = "";                // SMTP Port. ( None )
$config['smtp_timeout']    = 5;                // SMTP Timeout (in seconds). ( None )

$config['wordwrap']        = TRUE;                // Enable word-wrap. ( TRUE or FALSE (boolean) )
$config['wrapchars']    = "76";                // Character count to wrap at. ( None )

$config['mailtype']        = "html";            // Type of mail. If you send HTML email you must send it as a complete web page. ( text or html )
                                            // 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.). ( None )
$config['validate']        = FALSE;            // Whether to validate the email address. ( TRUE or FALSE (boolean) )
$config['priority']        = "3";                // Email Priority. 1 = highest. 5 = lowest. 3 = normal. ( 1, 2, 3, 4, 5 )
$config['crlf']            = "\r\n";            // Newline character. (Use "\r\n" to comply with RFC 822). ( "\r\n" or "\n" or "\r" )
$config['newline']        = "\r\n";            // Newline character. (Use "\r\n" to comply with RFC 822). ( "\r\n" or "\n" or "\r" )

$config['bcc_batch_mode']    = FALSE;        // Enable BCC Batch Mode. ( TRUE or FALSE (boolean) )
$config['bcc_batch_size']    = 200;            // Number of emails in each BCC batch. ( None )


// ------------------------------------------------------------------------
/* End of file email.php */
/* Location: ./application/config/email.php */

InsiteFX

#14
[eluser]InsiteFX[/eluser]
Email_test - Controller - application/controllers/email_test
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/**
* Name Class Controller
*
* @package        CodeIgniter
* @subpackage    Controllers
* @category    Controllers
* @author        Raymond King aka:(InsiteFX).
* @copyright    Copyright (c) 2005 - 2011, Advanced Computer Systems, LLC.
* @license        http://www.learncodeigniter.com
* @link        http://www.learncodeigniter.com
* @since        Version 1.0.0
*/

class Email_test extends CI_Controller {

    // Class Variables.
    // --------------------------------------------------------------------


    // --------------------------------------------------------------------

    /**
     * __construct
     *
     * PHP 5+    Constructor
     *
     * Not need if not setting up parameters etc.
     *
     * @access    public
     * @return    void
     */
    public function __construct()
    {
        parent::__construct();
    }

    // --------------------------------------------------------------------

    /**
     * index()
     *
     * Default Controller index method.
     *
     * @access    public
     * @return    void
     */
    public function index()
    {

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

        $this->email->from('[email protected]', 'Your Name');
        $this->email->to('[email protected]');
        $this->email->cc('[email protected]');
        $this->email->bcc('[email protected]');

        $this->email->subject('Email Test');
        $this->email->message('Testing the email class.');

        $this->email->send();

        // Load this controllers Data and View.
        $this->load->view('email_message');
    }

}

// ------------------------------------------------------------------------
/* End of file email_test.php */
/* Location: ./application/controllers/email_test.php */

InsiteFX

#15
[eluser]InsiteFX[/eluser]
Email_message - View - application/views/email_message
Code:
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
    &lt;meta charset="utf-8"&gt;
    &lt;title&gt;Welcome to CodeIgniter&lt;/title&gt;

&lt;style type="text/css"&gt;

body {
background-color: #fff;
margin: 40px;
font-family: Lucida Grande, Verdana, Sans-serif;
font-size: 14px;
color: #4F5155;
}

a {
color: #003399;
background-color: transparent;
font-weight: normal;
}

h1 {
color: #444;
background-color: transparent;
border-bottom: 1px solid #D0D0D0;
font-size: 16px;
font-weight: bold;
margin: 24px 0 2px 0;
padding: 5px 0 6px 0;
}

code {
font-family: Monaco, Verdana, Sans-serif;
font-size: 12px;
background-color: #f9f9f9;
border: 1px solid #D0D0D0;
color: #002166;
display: block;
margin: 14px 0 14px 0;
padding: 12px 10px 12px 10px;
}

&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

<h1>Welcome to CodeIgniter!</h1>

<p>The page you are looking at is being generated dynamically by CodeIgniter.</p>

<p>If you would like to edit this page you'll find it located at:</p>
<code>application/views/welcome_message.php</code>

<p>The corresponding controller for this page is found at:</p>
<code>application/controllers/welcome.php</code>

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a href="user_guide/">User Guide</a>.</p>

&lt;?php echo $this->email->print_debugger();?&gt;

<p><br />Page rendered in {elapsed_time} seconds</p>

&lt;/body&gt;
&lt;/html&gt;

InsiteFX

#16
[eluser]Madmartigan1[/eluser]
@InsiteFX: So to get Test Mail Server working, you literally did NO configuration to the CI email class and just used all default settings?

I tried setting protocol to 'smtp', with everything else default, then tried different values for the smtp_host, including 'localhost', '127.0.0.1', '192.168.1.100', and ''.

There are like zero options for the mail server so I am clueless. Can you confirm that you indeed have sent test mails locally with that tool?

Here is my php.ini:

Code:
[mail function]
; For Win32 only.
SMTP = 192.168.1.100
smtp_port = 25

; For Win32 only.
sendmail_from = [email protected]

Here is my result using php's native mail() function:

Quote:Failed to connect to mailserver at "192.168.1.100" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set()

#17
[eluser]InsiteFX[/eluser]
I am using the mail protocol, you do not need to specify the smtp port just leave it blank!

Look at the email.php file I incude to go in to your application/config/email.php

The email library will load it from the config folder. Use that file and everything should work.

I am running Windows 7 Pro 64-bit

InsiteFX

#18
[eluser]InsiteFX[/eluser]
@raiser

If your running on your local host you probabily do not have sendmail!

If your trying to use smtp then it will all depend on your server configuration.

Thats why I use the mail function for localhost.

InsiteFX

#19
[eluser]Madmartigan1[/eluser]
Using the mail protocol and empty string for port:

Quote:Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.

This is starting to feel familiar. I will most likely give up and go back to var_dump()ing the email object for debugging purposes locally. I just don't know what I'm doing. Thanks for the help InsiteFX, if you have any other pointers I will be listening.

@raiser: Sorry to hijack your thread!

#20
[eluser]InsiteFX[/eluser]
Ok, I have figured out what you have to do to use all email features including SMTP

NOTE: I have tested everyone of the email Protocols on my system and everyone of them works!
mail
sendmail
smtp

Here is a new email.php file with commented Notes: on each line.
You have to use your own online SMTP server and make a few small changes to php.ini!
Code:
&lt;?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
/*
|-------------------------------------------------------------------------
| Name: email.php
|-------------------------------------------------------------------------
|
|-------------------------------------------------------------------------
*/

$config['useragent']    = "CodeIgniter";    // The "user agent". ( None )
$config['protocol']        = "smtp";        // The mail sending protocol. ( mail, sendmail, or smtp )
$config['mailpath']        = "";                // The server path to Sendmail. ( None )

$config['smtp_host']    = "";                   // SMTP Server Address. ( None ) NOTE: This is your real account SMTP server online that you setup in your email application
$config['smtp_user']    = "";                   // SMTP Username. ( None ) NOTE: This your real online email account name that you setup in your email application!
$config['smtp_pass']    = "";                // SMTP Password. ( None ) NOTE: This is the real PASSWORD that you use to logon to your real email accout!
$config['smtp_port']    = "25";                // SMTP Port. ( None ) NOTE: Your real online SMTP PORT NUMBER, mine is 25
$config['smtp_timeout']    = 5;                // SMTP Timeout (in seconds). ( None )

$config['wordwrap']        = TRUE;                // Enable word-wrap. ( TRUE or FALSE (boolean) )
$config['wrapchars']    = "76";                // Character count to wrap at. ( None )

$config['mailtype']        = "html";            // Type of mail. If you send HTML email you must send it as a complete web page. ( text or html )
                                            // 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.). ( None )
$config['validate']        = FALSE;            // Whether to validate the email address. ( TRUE or FALSE (boolean) )
$config['priority']        = "3";                // Email Priority. 1 = highest. 5 = lowest. 3 = normal. ( 1, 2, 3, 4, 5 )
$config['crlf']            = "\r\n";            // Newline character. (Use "\r\n" to comply with RFC 822). ( "\r\n" or "\n" or "\r" )
$config['newline']        = "\r\n";            // Newline character. (Use "\r\n" to comply with RFC 822). ( "\r\n" or "\n" or "\r" )

$config['bcc_batch_mode']    = FALSE;        // Enable BCC Batch Mode. ( TRUE or FALSE (boolean) )
$config['bcc_batch_size']    = 200;            // Number of emails in each BCC batch. ( None )

/**
* Note: This is for XAMMP but should be something like it for MAPP and WAMP
* Settings for php.ini
*
* SMTP Settings - php.ini
*
* [mail function]
* ; For Win32 only.
* ; http://php.net/smtp
* ; BELOW - assign this your real smtp server for your online account <--- READ
* SMTP = smtp.yoursite.com
* ; http://php.net/smtp-port
* smtp_port = 25
*
* ; For Win32 only.
* ; http://php.net/sendmail-from
* ; BELOW - your real email address her from your online account <--- READ
* sendmail_from = [email protected]
*
* ; For Unix only.  You may supply arguments as well (default: "sendmail -t -i").
* ; http://php.net/sendmail-path
* ; BELOW - For sendmail
* sendmail_path = "\"C:\xampp\sendmail\sendmail.exe\" -t"
*
* ; Force the addition of the specified parameters to be passed as extra parameters
* ; to the sendmail binary. These parameters will always replace the value of
* ; the 5th parameter to mail(), even in safe mode.
* ;mail.force_extra_parameters =
*
* ; Add X-PHP-Originating-Script: that will include uid of the script followed by the filename
* mail.add_x_header = On
*
* ; Log all mail() calls including the full path of the script, line #, to address and headers
* ;mail.log = "C:\xampp\apache\logs\php_mail.log"
*
*/

// ------------------------------------------------------------------------
/* End of file email.php */
/* Location: ./application/config/email.php */
Follow the above and all three email protocols should work just fine!

InsiteFX


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.