CodeIgniter Forums
Email Failed when sending attachment - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Email Failed when sending attachment (/thread-58301.html)



Email Failed when sending attachment - El Forum - 05-31-2013

[eluser]pengenbelajarCI[/eluser]
Hi,

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

Code:
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: "[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"


=?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
Code:
$config['set_newline'] = "\r\n";
$config['mailtype'] = 'html';
$config['charset'] = 'iso-8859-1';
$config['wordwrap'] = TRUE;

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

$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

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



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

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

$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" .
"-{$mime_boundary}-\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?