PHP自定义SMTP邮件功能返回ERROR fputs发送字节失败errno = 32管道损坏
内容导读
互联网集市收集整理的这篇技术教程文章主要介绍了PHP自定义SMTP邮件功能返回ERROR fputs发送字节失败errno = 32管道损坏,小编现在分享给大家,供广大互联网技能从业者学习和参考。文章包含3689字,纯文字阅读大概需要6分钟。
内容图文
![PHP自定义SMTP邮件功能返回ERROR fputs发送字节失败errno = 32管道损坏](/upload/InfoBanner/zyjiaocheng/783/35bd8b8ddeda4540bf1f01980764d263.jpg)
我编写了下一个自定义PHP函数来通过SMTP邮件服务器发送邮件.
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;
}
该功能运行良好,但在最后几天我收到了nexts php错误:
注意:fputs()[function.fputs]:发送8192个字节失败,错误为errno = 32第165行/cakeapp/trunk/app/controllers/components/email.php中的管道损坏
注意:fputs()[function.fputs]:发送49个字节失败,errno = 32第169行/cakeapp/trunk/app/controllers/components/email.php中的管道损坏
注意:fputs()[function.fputs]:发送6个字节失败,errno = 32在第182行的/cakeapp/trunk/app/controllers/components/email.php中断管
我在谷歌搜索了一些建议,但我找到的信息,谈到了与连接超时相关的问题!
任何人都可以提出解决这个问题的方法吗?
解决方法:
我有同样的问题,并通过将协议设置为’邮件’找到解决方案(当然,这不是总是你需要使用“邮件”作为协议的情况,我在另一个网站使用“smtp”作为协议,并且工作正常,但我为其他网站复制和粘贴的相同代码并没有工作,所以我不得不将其更改为“邮件”).我的示例配置如下所示(用您自己的凭据替换大写单词):
'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,// The default value
'mailtype' => 'html' //default: text
内容总结
以上是互联网集市为您收集整理的PHP自定义SMTP邮件功能返回ERROR fputs发送字节失败errno = 32管道损坏全部内容,希望文章能够帮你解决PHP自定义SMTP邮件功能返回ERROR fputs发送字节失败errno = 32管道损坏所遇到的程序开发问题。 如果觉得互联网集市技术教程内容还不错,欢迎将互联网集市网站推荐给程序员好友。
内容备注
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 gblab@vip.qq.com 举报,一经查实,本站将立刻删除。
内容手机端
扫描二维码推送至手机访问。