SitePoint Sponsor |
|
User Tag List
Results 1 to 5 of 5
Thread: email with attachment
-
Jul 13, 2007, 10:11 #1
- Join Date
- Oct 2006
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
email with attachment
Hi,
I'm trying to send an email with an attachment on a windows and I'm running into problems. I don't get any errors but the email is not being sent for sending the mail.
My code is below:
PHP Code:// Generate a boundary string
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
// Add the headers for a file attachment
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";
// Add a multipart boundary above the plain message
$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";
echo $message;
// Base64 encode the file data
$data = chunk_split(base64_encode($data));
//echo $data;
// Add file attachment to the message
$message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";
}
// Send the message
$ok = @mail($to, $subject, $message, $headers);
if ($ok) {
echo "<p>Mail sent! Yay PHP!</p>";
} else {
echo "<p>Mail could not be sent. Sorry!</p>";
}
-
Jul 13, 2007, 10:40 #2
- Join Date
- Feb 2004
- Location
- Tampa, FL (US)
- Posts
- 9,854
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
any particular reason you're trying to reinvent the wheel re: MIME encoding? there are plenty of proven libraries out there for that. for example, PEAR.
-
Jul 13, 2007, 10:43 #3
- Join Date
- Oct 2006
- Posts
- 22
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Novice
Well because I'm a novice and I can't really explain how to install things to my boss. It hard going back and forth with php.ini files and file installations especially since I don't have access to the server where everything is located and I constantly have to bother him when things aren't working. I do know this is the long way around but it's less a pain in the butt in that respect.
-
Jul 13, 2007, 11:00 #4
- Join Date
- Oct 2006
- Location
- Kathmandu, Nepal
- Posts
- 4,013
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
I will suggest you to download PHPMailer and use it. that will work for you perfectly which i am using since last 1 year. Simple steps are there to integrate too. But i have not worked yet with Windows servers.
Mistakes are proof that you are trying.....
------------------------------------------------------------------------
PSD to HTML - SlicingArt.com | Personal Blog | ZCE - PHP 5
-
Jul 13, 2007, 11:31 #5
- Join Date
- Feb 2004
- Location
- Tampa, FL (US)
- Posts
- 9,854
- Mentioned
- 1 Post(s)
- Tagged
- 0 Thread(s)
you don't need access to the ini files and such to use PEAR.
Bookmarks