简体   繁体   English

发送附件时电子邮件失败

[英]Email failed when sending attachment

I just moved my website from one hosting company to another. 我只是将网站从一家托管公司转移到了另一家托管公司。 But in the process, my email function doesn't work if I send with an attachment. 但是在此过程中,如果我发送附件,则我的电子邮件功能不起作用。

This is from the debugger: 这来自调试器:

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

This is my code 这是我的代码

$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();

But if I send email with attachments using a library outside CI, it's working. 但是,如果我使用CI外部的库发送带有附件的电子邮件,则可以正常工作。 Actually, my solution right now is to make a helper for sending mail not using the CI library. 实际上,我现在的解决方案是为不使用CI库发送邮件提供帮助。 But if there's any way I could still using CI library, it would be great. 但是,如果我仍然可以使用CI库的任何方式,那就太好了。

I had the same problem and was able to solve it by changing the email.php file in system/libraries folder of codeigniter 我有同样的问题,可以通过更改codeigniter的system / libraries文件夹中的email.php文件来解决

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

The problem seemed to be the mail protocol in the first line above. 问题似乎是上面第一行中的邮件协议。

You may also have to add username and the password in teh next two lines if you have those setup 如果已进行设置,则可能还需要在接下来的两行中添加用户名和密码

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM