Welcome Guest, Not a member yet? Register   Sign In
Email Failed when sending attachment


I just move my website from one hosting company to another. But in the process, my email function doesn't work if i sending it with 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"
Reply-To: "[email protected]"
X-Sender: [email protected]
X-Mailer: CodeIgniter
X-Priority: 3 (Normal)
Message-ID: <[email protected]>
Mime-Version: 1.0
Content-Type: multipart/mixed; boundary="B_ATC_51a901aa74aa0"

This is a multi-part message in MIME format.
Your email application may not support this format.

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

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

Testing the email class.

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

Testing the email class.


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->from('[email protected]', 'Me');
$this->email->to('[email protected]');
$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

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

I try to send email not using CI, like on this code below
$fileatt = "screenshot.png";
$fileatttype = "image/png";
$fileattname = "screenshot.png";
$headers = "From: $from";

$file = fopen($fileatt, 'rb');
$data = fread($file, filesize($fileatt));

$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.\n\n" .
"-{$mime_boundary}\n" .
"Content-Type: text/plain; charset=\"iso-8859-1\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
$message .= "\n\n";

$data = chunk_split(base64_encode($data));
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatttype};\n" .
" name=\"{$fileattname}\"\n" .
"Content-Disposition: attachment;\n" .
" filename=\"{$fileattname}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .

if(mail($to, $subject, $message, $headers)) {
    echo "The email was sent.";
} else {
    echo "There was an error sending the mail.";

And this thing is work. So what do i miss?

Theme © iAndrew 2016 - Forum software by © MyBB