It will be better to if u post ur code
you can try this code this code to send a mail with attachment
<form name='MyExampleForm' action='example.php' method='post' enctype='multipart/form-data'>
<input type='file' name='uploaded_file'>
<input type='submit' value='Submit file!'>
</form>
example.php
<?php
// include the class
include("mailer.php");
// your email
$recipient = "
myemail@mydomain.com";
// person sending it
$from = "
me@mydomain.com";
// subject
$subject = "A new file has been submitted!";
// email message
$message = "A new file has been submitted!";
// where to move file to once uploaded
$uploadedFolder = "/home/username/public_html/uploaded/";
// initialize email object (to, from, subject)
$myEmail = new EPDev_Emailer($recipient, $from, $subject);
// Add the message to the email
$myEmail->addText($message);
if (!empty($_FILES['uploaded_file']['name']))
{
// move the file from tmp to a folder
move_uploaded_file($_FILES['uploaded_file']['tmp_name'], $uploadedFolder . basename($_FILES['uploaded_file']['name']));
// add as file attachment to email message
$result = $myEmail->addFile($uploadedFolder . basename($_FILES['uploaded_file']['name']), $_FILES['uploaded_file']['type']);
if (!$result)
die("Problem adding file to email!");
}
else
{
die("nothing uploaded!");
}
// actually send out the email
$myEmail->send();
mailer.php :
<?php
class EPDev_Emailer
{
var $message;
var $FILES;
var $EMAIL;
function EPDev_Emailer($to_address, $from_address, $subject, $reply_address=null, $cc_address, $bcc_address, $mailer=null, $custom_header=null)
{
$this->EMAIL = array(
"to" => $to_address,
"from" => $from_address,
"subject" => $subject,
"reply" => (empty($reply_address) ? $from_address : $reply_address),
"cc" => (empty($cc_address) ? "" : $cc_address),
"bcc" => (empty($bcc_address) ? "" : $bcc_address),
"mailer" => (empty($mailer) ? "X-Mailer: PHP/" . phpversion() : $mailer),
"header" => (empty($custom_header) ? "" : $custom_header),
"boundary" => "_mimeboundary_".md5(uniqid(mt_rand(), 1))
);
$this->message = "";
$this->FILES = array();
}
function addFile($filename, $type=null, $filecontents=null)
{
if ($filecontents !== null)
{
$index = count($this->FILES);
$this->FILES[$index]['data'] = chunk_split(base64_encode($filecontents));
$this->FILES[$index]['name'] = basename($filename);
if (empty($type))
$this->FILES[$index]['mime'] = mime_content_type($filename);
else
$this->FILES[$index]['mime'] = $type;
}
else if (file_exists($filename))
{
$index = count($this->FILES);
$this->FILES[$index]['data'] = chunk_split(base64_encode(file_get_contents($filen ame)));
$this->FILES[$index]['name'] = basename($filename);
if (empty($type))
$this->FILES[$index]['mime'] = mime_content_type($filename);
else
$this->FILES[$index]['mime'] = $type;
}
else
{
return false;
}
return true;
}
function addText($text)
{
$this->message .= $text;
}
function getHeader()
{
$header = "From: {$this->EMAIL['from']}\r\n"
. "Reply-To: {$this->EMAIL['reply']}\r\n"
. (!empty($this->EMAIL['cc']) ? "Cc: {$this->EMAIL['cc']}\r\n" : "")
. (!empty($this->EMAIL['bcc']) ? "Bcc: {$this->EMAIL['bcc']}\r\n" : "")
. "X-Mailer: {$this->EMAIL['mailer']}\r\n"
. "MIME-Version: 1.0\r\n"
. "Content-Type: multipart/mixed; boundary=\"{$this->EMAIL['boundary']}\";\r\n";
return $header;
}
function getEmail()
{
$content .= "--{$this->EMAIL['boundary']}\r\n"
. "Content-Type: text/plain; charset=\"iso-8859-1\"\r\n"
. "Content-Transfer-Encoding: 7bit\r\n\r\n"
. $this->message . "\r\n";
if (!empty($this->FILES))
{
foreach($this->FILES as $file)
{
$content .= "--{$this->EMAIL['boundary']}\r\n"
. "Content-Type: {$file['mime']}; name=\"{$file['name']}\"\r\n"
. "Content-Transfer-Encoding: base64\r\n"
. "Content-Disposition: attachment\r\n\r\n"
. $file['data'] . "\r\n";
}
}
$content .= "--{$this->EMAIL['boundary']}--\r\n";
return $content;
}
function send()
{
return mail($this->EMAIL['to'], $this->EMAIL['subject'], $this->getEmail(), $this->getHeader());
}
}