Jump to content

[SOLVED] file attahment in mail help!


Stickybomb

Recommended Posts

ok i am working on a form and need to provide the ability to attach an image in the mail that will be sent. for some reason though it is not sending the mail

 

<?php
//initalized form variables
$firstname='';
$lastname='';
$mailing='';
$shipping='';
$phone='';
$fax='';
$email='';
$contactname='';
$company='';
$comments='';
$quantity='';

//header check array
$check = array("%0A", "%0D", "bcc:", "cc:", "mime-type:", "content-type:", "from:", "to:", "Bcc:", "Cc:", "Mime-Type:", "Content-Type:", "From:", "To:", "\\r", "\\n", "\\" );
$error=0;

if(isset($_POST['submitted']) == "yes"){

if(!empty($_POST['firstname'])){$firstname = $_POST['firstname'];}else{$firstname='';}
if(!empty($_POST['lastname'])){$lastname = $_POST['lastname'];}else{$lastname='';}
if(!empty($_POST['mailing'])){$$mailing = $_POST['mailing'];}else{$mailing='';}
if(!empty($_POST['shipping'])){$shipping = $_POST['shipping'];}else{$shipping='';}
if(!empty($_POST['phone'])){$phone = $_POST['phone'];}else{$phone='';}
if(!empty($_POST['fax'])){$fax = $_POST['fax'];}else{$fax='';}
if(!empty($_POST['contactname'])){$contactname = $_POST['contactname'];}else{$contactname='';}
if(!empty($_POST['company'])){$company = $_POST['company'];}else{$company='';}
if(!empty($_POST['quantity'])){$quantity = $_POST['quantity'];}else{$quantity='';}
if(!empty($_POST['comments'])){$comments = $_POST['comments'];}else{$comments='';}

//check for injections
$firstname = str_replace($check, "", $firstname);
$lastname = str_replace($check, "", $lastname);
$mailing = str_replace($check, "", $mailing);
$shipping = str_replace($check, "", $shipping);
$phone = str_replace($check, "", $phone);
$fax = str_replace($check, "", $fax);
$contactname = str_replace($check, "", $contactname);
$company = str_replace($check, "", $company);
$quantity = str_replace($check, "", $quantity);
$comments = str_replace($check, "", $comments);

if (eregi('<a href',$firstname)){$error=1;}
if (eregi('<a href',$lastname)){$error=1;}
if (eregi('<a href',$mailing)){$error=1;}
if (eregi('<a href',$shipping)){$error=1;}
if (eregi('<a href',$phone)){$error=1;}
if (eregi('<a href',$fax)){$error=1;}
if (eregi('<a href',$contactname)){$error=1;}
if (eregi('<a href',$company)){$error=1;}
if (eregi('<a href',$quantity)){$error=1;}
if (eregi('<a href',$comments)){$error=1;}

if($error!=1){
//create message
$to='[email protected]';
$subject='Quote Request';
$message=
"The following quote request was submitted:\n
First Name - ". $firstname . "\n
Last Name - ". $lastname . "\n
Company - ". $company . "\n
Mailing Address - ". $mailing . "\n
Shipping Address - ". $shipping . "\n
Phone - ". $phone . "\n
Fax - ". $fax . "\n
E-Mail - ". $email . "\n
Contact Name - ". $contactname . "\n
Quoe Quantity - ". $quantity . "\n
Comments - " . $comments."\n";

$fileatt = $_FILES['fileatt']['tmp_name']; 
$fileatt_type = $_FILES['fileatt']['type']; 
$fileatt_name	= $_FILES['fileatt']['name'];

$headers = 'From: '.$company ."\r\n";
$headers .= 'Bcc: ';
$headers .= 'Cc: ';

if (is_uploaded_file($fileatt)) {
$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=\"utf-8\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" . 
$message . "\n\n";

$data = chunk_split(base64_encode($data));
$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 results
$ok=@mail($to, $subject, $message, $headers); 

if ($ok) { 
echo "<p>Thank you! Your request has been successfully submited.</p>"; 
} else { 
echo "<p>Request could not be sent. Sorry! (01)</p>"; 
} 
}else{
echo "<p>Request could not be sent. Sorry! 02</p>"; 
}
//Else display form

 

i am getting the error msg i created with the (01) appended to it which implies that the ok variable is not recieving a value it is the exact same method i am using on another form i created which works fine, the only difference is the fields them self the other one has less fields then this one.

 

Link to comment
https://forums.phpfreaks.com/topic/56065-solved-file-attahment-in-mail-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.