Can anyone guide me I want to send attachment with my mail and I'm using http://demo.tutorialzine.com/2013/05...e-upload-form/ plugin instead of simple , the issue is occurring when I'm sending mail using above given plugin I'm not receiving attachment and when I'm simply put it works perfectly. So I need to work it when I selected files like in the given plugin.
PHP code that I've added is:
$errors = '';
$to = "my email id";
if(empty($_POST['name']) ||
empty($_POST['email']) ||
empty($_POST['website']))
{
$errors .= "
Error: all fields are required";
}
$name = $_POST['name'];
$email_address = $_POST['email'];
$website = $_POST['website'];
$company = $_POST['company'];
if (!preg_match(
"/^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$/i",
$email_address))
{
$errors .= "
Error: Invalid email address";
}
function getSiteTitle(){
$RefURL = (is_null($_SERVER['HTTP_REFERER'])) ? 'Un know' : $_SERVER['HTTP_REFERER'];
if($RefURL != 'Un know'){
$con = file_get_contents($RefURL) or die (" can't open URL referer ");
$pattern = "/<title>(.+)<\/title>/i";
preg_match($pattern,$con,$match);
$result = array($match[1],$RefURL);
return $result;
}
else{
return false;
}
}
$info = getSiteTitle();
$subject = $info[0];
$message = "Message goes here..".
"Here are the details:
Name : $name
Email : $email_address
Website : $website
Company : $company";
$headers = "From: $to
";
$headers .= "Reply-To: $email_address";
$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x";
$headers = "From: $to
" .
"MIME-Version: 1.0
" .
"Content-Type: multipart/mixed;
" .
" boundary=\"{$mime_boundary}\"";
$message = "This is a multi-part message in MIME format.
" .
"--{$mime_boundary}
" .
"Content-Type: text/plain; charset=\"iso-8859-1\"
" .
"Content-Transfer-Encoding: 7bit
" .
$message . "
";
foreach($_FILES as $userfile)
{
$tmp_name = $userfile['attachFile'];
$type = $userfile['type'];
$name = $userfile['name'];
$size = $userfile['size'];
if (file_exists($tmp_name))
{
if(is_uploaded_file($tmp_name))
{
$file = fopen($tmp_name,'rb');
$data = fread($file,filesize($tmp_name));
fclose($file);
$data = chunk_split(base64_encode($data));
}
$message .= "--{$mime_boundary}
" .
"Content-Type: {$type};
" .
" name=\"{$name}\"
" .
"Content-Disposition: attachment;
" .
" filename=\"{$fileatt_name}\"
" .
"Content-Transfer-Encoding: base64
" .
$data . "
";
}
}
$message.="--{$mime_boundary}--
";
if (mail($to, $subject, $message, $headers))
header('Location: thank-you.html');
else
echo "Error in mail";
?>
Thanks in Advance!