Welcome Guest, Not a member yet? Register   Sign In
Sending Mail
#1

[eluser]Michael Nielsen[/eluser]
I'm using the CI email library and can't get a single email sent.

This is my controller:

Code:
<?
class Email extends Controller
{
    function Email()
    {
        parent::Controller();
    }
    function index()
    {
        $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxx',
        'smtp_pass' => 'xxx',
        'mailtype'  => 'text',
        'charset'   => 'iso-8859-1',
        'wordwrap'  => TRUE
        );

        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");

        $this->email->from('xxx');
        $this->email->to('xxx');
        $this->email->subject('This is an email test');
        $this->email->message('It is working. Great!');

        if($this->email->send())
        {
            echo 'Your email was sent, fool.';
        }

        else
        {
            show_error($this->email->print_debugger());
        }
    }
}
?>

I'm using Google Apps to host my email so I'm assuming I can use it to send emails from my company domain instead of a @gmail.com.

I'm also generating a whopping 14 errors when I execute the controller.

Code:
A PHP Error was encountered

Severity: Warning

Message: fsockopen() [function.fsockopen]: unable to connect to ssl://smtp.googlemail.com:465 (Unable to find the socket transport "ssl" - did you forget to enable it when you configured PHP?)

Filename: libraries/Email.php

Line Number: 1652

Theres about 3 million fgets and fwrites errors.

Code:
A PHP Error was encountered

Severity: Warning

Message: fwrite(): supplied argument is not a valid stream resource

Filename: libraries/Email.php

Line Number: 1795

Code:
A PHP Error was encountered

Severity: Warning

Message: fgets(): supplied argument is not a valid stream resource

Filename: libraries/Email.php

Line Number: 1818

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\system\libraries\Exceptions.php:166)

Filename: codeigniter/Common.php

Line Number: 360

thanks in advance.
#2

[eluser]imn.codeartist[/eluser]
enable

extension=php_openssl.dll in your php.ini and restart apache

this should allow you to send email
#3

[eluser]Michael Nielsen[/eluser]
no. still giving the same error. I even tired using an @gmail.com address.
#4

[eluser]imn.codeartist[/eluser]
I used the same code and tested in my local as it was giving same error before but once i enabled the ssl extension that i posted earlier then it just worked.
#5

[eluser]Michael Nielsen[/eluser]
does this error make any sense to you?

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\Program Files\Apache Software Foundation\Apache2.2\htdocs\system\libraries\Exceptions.php:166)

Filename: codeigniter/Common.php

Line Number: 360
#6

[eluser]imn.codeartist[/eluser]
did you modify the core files of Codeigniter ??
#7

[eluser]imn.codeartist[/eluser]
This is the class and I renamed it with Emailer as there is already Email class in the CI library and that may produce conflict... Try this one
Code:
<?
class Emailer extends Controller
{
    function Emailer()
    {
        parent::Controller();
    }
    function index()
    {
        $config = Array(
        'protocol' => 'smtp',
        'smtp_host' => 'ssl://smtp.googlemail.com',
        'smtp_port' => 465,
        'smtp_user' => 'xxxxx',
        'smtp_pass' => 'xxxxxx',
        'mailtype'  => 'text',
        'charset'   => 'iso-8859-1',
        'wordwrap'  => TRUE
        );

        $this->load->library('email', $config);
        $this->email->set_newline("\r\n");

        $this->email->from('[email protected]');
        $this->email->to('[email protected]');
        $this->email->subject('This is an email test');
        $this->email->message('It is working. Great!');

        if($this->email->send())
        {
            echo 'Your email was sent, fool.';
        }

        else
        {
            show_error($this->email->print_debugger());
        }
    }
}
#8

[eluser]Michael Nielsen[/eluser]
nup i still get the same error. is something wrong with my php config??
#9

[eluser]imn.codeartist[/eluser]
Then must be something wrong with your php configuration or try reinstalling codeigniter
#10

[eluser]Unknown[/eluser]
Hi,

Don't know how helpful this will be but the fsockopen error may be an indication that you are running this on windows. fsockopen is broken in windows. Not sure how to fix it but maybe it's a direction worth exploring.

jephroni




Theme © iAndrew 2016 - Forum software by © MyBB