10

While sending an email, I'm receiving a bunch of such errors:

A PHP Error was encountered

Severity: Notice

Message: fwrite(): send of 12 bytes failed with errno=32 Broken pipe

Filename: libraries/Email.php

Line Number: 1846

A PHP Error was encountered

Severity: Notice

Message: fwrite(): send of 39 bytes failed with errno=32 Broken pipe

Filename: libraries/Email.php

Line Number: 1846

A PHP Error was encountered

Severity: Notice

Message: fwrite(): send of 31 bytes failed with errno=32 Broken pipe

Filename: libraries/Email.php

Line Number: 1846

I have followed the CodeIgniter user guide to configure an SMTP:

$config['protocol']='smtp';  
$config['smtp_host']='ssl0.ovh.net';  
$config['smtp_port']='465';  
$config['smtp_timeout']='10';  
$config['smtp_user']='postmaster%example.com';  
$config['smtp_pass']='password';
$config['mailtype'] = 'html';
$config['charset'] = 'utf-8';
$config['newline'] = "\r\n";
$config['useragent'] = 'Project';

It seems like the configuration file is just fine, and correct (I've checked the OVH's email configuration files).

Any solution for that?

Scott
  • 5,991
  • 15
  • 35
  • 42
  • 10
    Try to change protocol from `smtp` to `mail`. I haven't checked, but google tells, it may work. – Edward Ruchevits Dec 04 '12 at 00:56
  • @EdwardRuchevits It worked, but are you sure it is using the OVH mailing service and not the send mail or installed postfix or something like that? I have tested it , and even if I would enter the wrong password, it would still send the message so it's not working. – Scott Dec 04 '12 at 02:36
  • it uses standard send mail. As to your question, this one looks similar: http://stackoverflow.com/questions/1555145/sending-email-with-gmail-smtp-with-codeigniter-email-library – Edward Ruchevits Dec 04 '12 at 08:20
  • 3
    it is because of your port! use 465 for SSL connection alone! for rest use 25 as port!! – Sam Arul Raj T Oct 07 '13 at 13:55
  • I answered the same problem here: http://stackoverflow.com/questions/4338950/php-custom-smtp-mail-function-return-error-fputs-send-bytes-failed-errno-32-brok/19333459#19333459 – Musa Haidari Oct 12 '13 at 11:18
  • @Edward Ruchevits given very best answer saved my hours – kailas Oct 24 '16 at 12:09

7 Answers7

11

I too was in the same situation. Was getting:

Message: fwrite(): SSL: Broken pipe</p><p>Filename: libraries/Email.php</p><p>Line Number: 2250&

the change that really made a difference was the 'smtp_crypto' config option set to 'ssl'

$config['protocol'] = 'smtp';
$config['smtp_host'] = 'ssl://example.com';
$config['smtp_crypto'] = 'ssl';
$config['smtp_port'] = '465';
$config['smtp_user'] = 'user@example.com';
$config['smtp_pass'] = 'password';
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = 'TRUE';

I found this solution at https://www.codeigniter.com/user_guide/libraries/email.html by searching for SSL option.

Stefan P
  • 111
  • 1
  • 3
7

This is the answer that worked for me

http://biostall.com/resolving-error-with-sending-emails-via-smtp-using-codeigniter/

Be sure to use "\r\n" and not '\r\n'

Also you can set this in a config file:

$config['newline'] = "\r\n";
$config['crlf'] = "\r\n";
B. Assem
  • 1,058
  • 9
  • 12
5

If you are using cpanel for your website smtp restrictions are problem and cause this error.

SMTP Restrictions

This feature prevents users from bypassing the mail server to send mail, a common practice used by spammers. It will allow only the MTA, mailman, and root to connect to remote SMTP servers.

This control is also adjustable in Tweak Settings.

This setting has been updated.

The SMTP restriction is disabled.

I had a similar problem and had to disable SMTP Restrictions. After that all was ok.

pregmatch
  • 2,629
  • 6
  • 31
  • 68
3

As far as CI is concerned, there are so many issues with your email config array that could cause this error.

If you are on local development enviroment, Try changing capitalization for "smtp" to "SMTP" with capital letters.

If you are on a live server, try changing them to small caps.

All in all playing with $config['protocol'] = 'smtp' capitalization some times helps.

katwekibs
  • 1,342
  • 14
  • 17
  • Simple answer, the capitalization is the main error. changing SMTP to capital letters will solve the problem, test it and it worked like a charm! Vote up. – Burhan Kashour Feb 01 '21 at 20:09
2

Same problem here... but what worked for me was these set of configuration:

$config['protocol']     = 'smtp';
$config['smtp_host']    = XXX;
$config['smtp_user']    = XXX;
$config['smtp_port']    = 25; // was 465
$config['smtp_pass']    = XXX;
$config['newline']      = "\r\n";

And the message stopped. :D

ArtFranco
  • 300
  • 3
  • 10
0

use smpt_port:25, it's worked for me

Mang Jojot
  • 400
  • 4
  • 12
0

I try this and it's work for me

$config['protocol'] = 'smtp';
$config['smtp_crypto'] = 'tls';
$config['smtp_host'] = 'smtp.gmail.com';    
$config['smtp_port'] = '587';
Masjoel
  • 1
  • 1
  • Welcome to SO Masjoel! Code-only answers are discouraged here, as they provide no insight into how the problem was solved. Please update your solution with an explanation of how your code solves the problem at hand :) – Joel Oct 16 '18 at 00:31
  • Thanks for the advice, it seems to me less observing the problems above, sorry friends :( – Masjoel Oct 16 '18 at 01:00