email - PHP Custom SMTP Mail function Return ERROR fputs send bytes failed errno=32 Broken pipe -


i wrote next custom php function send mail trough smtp mail server.

function send($format = 'text'){      $smtpserver  = 'mail.mymailserver.com.mx';     $port        = '25';     $timeout     = '60';     $username    = 'myuser';     $password    = 'mypassword';     $localhost   = 'www.mydomain.com.mx';     $newline     = "\r\n";      $smtpconnect = fsockopen( $smtpserver, $port, $errno, $errstr, $timeout );      fputs( $smtpconnect,'auth login'.$newline );     fputs( $smtpconnect, base64_encode( $username )  . $newline    );     fputs( $smtpconnect, base64_encode( $password )  . $newline    );     fputs( $smtpconnect, 'helo '       . $localhost  . $newline    );     fputs( $smtpconnect, 'mail from: ' . $this->from . $newline    );     fputs( $smtpconnect, 'rcpt to: '   . $this->to   . $newline    );      if( !empty( $this->cc ) ){         fputs( $smtpconnect, 'rcpt to: '   . $this->cc   . $newline    );     }      if( !empty( $this->bcc ) ){         fputs( $smtpconnect, 'rcpt to: '   . $this->bcc  . $newline    );     }      fputs( $smtpconnect, 'data'        . $newline                  );      fflush( $smtpconnect );      $raw  = "";     $raw  = @fread( $smtpconnect, 255 ) . "@";     $raw .= @fread( $smtpconnect, 255 );      fputs( $smtpconnect, 'to:     '  . $this->to . $newline        );     fputs( $smtpconnect, 'from:   <' . $this->from .'>' . $newline );     fputs( $smtpconnect, 'subject:'  . $this->subject . $newline   );      $format = 'html';      if( $format == 'text' ){          $headers  = "content-type: text/plain; charset=\"iso-8859-1\"" . "\r\n";         $headers .= "content-transfer-encoding: 7bit" . "\r\n";          $message  = $this->bodytext();          fputs( $smtpconnect, $headers   . $newline  . $newline       );         fputs( $smtpconnect, $message   . $newline  . '.' . $newline );      }else{          $random_hash = md5(date('r', time()));          $headers  = "content-type: multipart/alternative; boundary=\"php-alt-".$random_hash."\"\r\n";         $headers .= "--php-alt-" . $random_hash . "\r\n";         $headers .= "content-type: text/plain; charset=\"iso-8859-1\"" . "\r\n";         $headers .= "content-transfer-encoding: 7bit" . "\r\n";          $message  = $this->bodytext();          fputs( $smtpconnect, $headers . $newline );         fputs( $smtpconnect, $message . $newline );          $headers  = "--php-alt-" . $random_hash . "\r\n";         $headers .= "content-type: text/html; charset=\"iso-8859-1\"" . "\r\n";         $headers .= "content-transfer-encoding: 7bit" . "\r\n";          $message  = $this->bodyhtml();          fputs( $smtpconnect, $headers  . $newline );         fputs( $smtpconnect, $message  . $newline );          $headers  = "--php-alt-" . $random_hash . "--\r\n";          fputs( $smtpconnect, $headers . '.' . $newline  );      }      fputs( $smtpconnect,'quit'      . $newline );      return true;  } 

the function working well, in last days recived nexts php errors:

notice: fputs() [function.fputs]: send of 8192 bytes failed errno=32 broken pipe in /cakeapp/trunk/app/controllers/components/email.php on line 165

notice: fputs() [function.fputs]: send of 49 bytes failed errno=32 broken pipe in /cakeapp/trunk/app/controllers/components/email.php on line 169

notice: fputs() [function.fputs]: send of 6 bytes failed errno=32 broken pipe in /cakeapp/trunk/app/controllers/components/email.php on line 182

i searching in google suggestions info found, talked problem related connection time outs !

can suggest way fix trouble ?

i had same problem , found solution setting protocol 'mail' (of course not case need use "mail" protocol, used "smtp" protocol in website, , working fine, same code copied , pasted other website , did not work, had change 'mail'). sample configuration looks this(replace uppercase words own credentials):

'protocol' => 'mail',             'smtp_host' => 'mail.your_website_domain.com.au',             'smtp_port' => 25,             'smtp_user' => 'your_email_account@your_website_domain.com.au',             'smtp_pass' => 'your_password_for_your_email_account',             'smtp_timeout' => 5,// default value             'mailtype' => 'html' //default: text         

Comments

Popular posts from this blog

asp.net - repeatedly call AddImageUrl(url) to assemble pdf document -

java - Android recognize cell phone with keyboard or not? -

iphone - How would you achieve a LED Scrolling effect? -