【问题标题】:Email failed when sending attachment发送附件时电子邮件失败
【发布时间】:2014-01-20 22:50:04
【问题描述】:

我刚刚将我的网站从一家托管公司转移到另一家托管公司。但在这个过程中,如果我发送附件,我的电子邮件功能将无法正常工作。

这是来自调试器:

Unable to send email using PHP mail(). Your server might not be configured to send mail using this method.
User-Agent: CodeIgniter
Date: Sat, 1 Jun 2013 03:01:46 +0700
From: "My name" 
Return-Path: 
Reply-To: "info@mysite.org" 
X-Sender: info@mysite.org
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <51a901aa74a21@mysite.org>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_51a901aa74aa0"


=?iso-8859-1?Q?Email_Test?=
This is a multi-part message in MIME format.
Your email application may not support this format.

--B_ATC_51a901aa74aa0
Content-Type: multipart/alternative; boundary="B_ALT_51a901aa74a67"

--B_ALT_51a901aa74a67
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit

Testing the email class.


--B_ALT_51a901aa74a67
Content-Type: text/html; charset=iso-8859-1
Content-Transfer-Encoding: quoted-printable

Testing the email class.

--B_ALT_51a901aa74a67--

--B_ATC_51a901aa74aa0
Content-type: image/png; name="screenshot.png"
Content-Disposition: attachment;
Content-Transfer-Encoding: base64

这是我的代码

$config['set_newline'] = "\r\n";
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

$this->email->initialize($config);

$this->email->from('me@mysite.org', 'Me');
$this->email->to('someone@someone.com'); 

$this->email->subject('Email Test');
$this->email->message('Testing the email class.'); 
$this->email->attach('screenshot.png'); //I put it on root directory of CI 

$this->email->send();
echo $this->email->print_debugger();

但是,如果我使用 CI 之外的库发送带有附件的电子邮件,它就可以正常工作。实际上,我现在的解决方案是制作一个不使用 CI 库发送邮件的助手。但是如果有什么方法我仍然可以使用 CI 库,那就太好了。

【问题讨论】:

  • 注释掉$this-&gt;email-&gt;attach('screenshot.png');这行是否有效?或者换一种说法:真的是附件导致了问题,还是 CodeIgniter 的电子邮件功能是如何配置的?
  • yap...如果我不附加任何文件,它将工作

标签: php codeigniter


【解决方案1】:

我遇到了同样的问题,我可以通过更改 codeigniter 的 system/libraries 文件夹中的 email.php 文件来解决它

var $protocol = "smtp"; // mail/sendmail/smtp
var $smtp_host = "localhost";  // SMTP Server.

问题似乎出在上面第一行的邮件协议上。

如果您有这些设置,您可能还需要在接下来的两行中添加用户名和密码

var $smtp_user = "my_username";  // SMTP Username
var $smtp_pass = "my_password";  // SMTP Password

【讨论】:

  • 我也遇到了一些问题,但我使用 sendmail 和它的罚款 $config['protocol'] = 'sendmail';
  • 尝试将其从 sendmail 更改为 smtp。看看能不能解决你的问题
猜你喜欢
  • 1970-01-01
  • 2013-08-26
  • 2017-12-08
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-02-09
  • 2013-03-03
相关资源
最近更新 更多