I Have visited a dozen of websites and registered with them but still none of them has helped me with my problem. I got a php script that i created that sends the results to a specific email address but the problem is that the attachments are not still working after countless attempts. THE ATTACHEDFILES DONT APPEAR IN THE MAIL.
SOME BODY PLEASE HELP ME .....................I REALLY NEED HELP AS SOON AS POSSIBLE.
HERE IS MY CODE PLEASE HELP WHERE HAVE GONE WRONG IN THE ATTACHMENTS PARTS.

<?php
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$day = $_POST['Day'];
$month = $_POST['Month'];
$year = $_POST['Year'];
$Gender = $_POST['Gender'];
$country = $_POST['country'];
$Province = $_POST['Province'];
$CityTown = $_POST['CityTown'];
$emailaddress = $_POST['EmailAddress'];

// Add file attachment to the message 
 $message .= "--{$mime_boundary}\n" . 
             "Content-Type: {$fileatt_type};\n" . 
             " name=\"{$picture_name}\"\n" . 
             "Content-Disposition: attachment;\n" . 
             " filename=\"{$fileatt_name}\"\n" . 
             "Content-Transfer-Encoding: base64\n\n" . 
             $data . "\n\n" . 
             "--{$mime_boundary}--\n"; 

$lookingfor = $_POST['LookingFor'];
$interestedin = $_POST['InterestedIn'];
$Duration = $_POST['Duration'];
$tnc_agree = $_POST['tnc_agree'];
	
$to = "ContiAds! <'datingavenue@contiads.co.za''mvity@yahoo.com'>";
$subject = "RE: New Dating Avenue SignUp!";
$body = "<html>".
	"<head>".
	"<title>Contact Request</title>".
	"<style type='text/css'>".
	"body,td,th {".
		"font-family: Geneva, Arial, Helvetica, sans-serif;".
		"font-size: 12px;".
	"}".
	".style1 {font-size: 24px}".
	"</style></head>".
	"<body>".
	"<p align='center' class='style1'>ContiAds New Signup</p>".
	"<table width='498' border='0' align='center' cellpadding='5' cellspacing='0'>".
	  "<tr>".
		"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
	  "</tr>".
	  "<tr>".
		"<td width='104' valign='top'>Full Name:</td>".
		"<td width='374'>".$firstname." ".$lastname."</td>".
	 "</tr>".
	  "<tr>".
		"<td valign='top'>Date:</td>".
		"<td>".$Date."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Month:</td>".
		"<td>".$month."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Year:</td>".
		"<td>".$year."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Gender:</td>".
		"<td>".$Gender."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Country:</td>".
		"<td>".$Country."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Province:</td>".
		"<td>".$Province."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Email Address:</td>".
		"<td>".$EmailAddress."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Looking For:</td>".
		"<td>".$lookingfor."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Interested In:</td>".
		"<td>".$InterestedIn."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Duration:</td>".
		"<td>".$Duration."</td>".
	  "</tr>".
	  "<tr>".
		"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
	  "</tr>".
	"</table>".
	"</body>".
	"</html>";

//Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
//$headers .= 'Cc: [email]myboss@example.com[/email]' . "\r\n";

if (mail($to, $subject, $body, $headers)) {
?>
<script language="javascript" type="text/javascript">
	location.replace("Sign%20Up%20Success.htm");
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
	location.replace("Sign%20Up%20Failure.htm");
</script>
<?php
}

?>

I dont see anywhere in your script where the values for the following variables are set:

$mime_boundary
$fileatt_type
$picture_name
$fileatt_name


It wont work if the values are empty.


Matti Ressler
Suomedia

Hi there

COULD YOU PLEASE HELP ME ON HOW YOU GO ABOUT DOING THAT AND FIXING THE PROBLEM BECAUSE AT THE PRESENT MOMENT I AM LOST AND VERY VERY CONFUSED!

Regards

Perhaps if you attach your form we can do something.


Matti Ressler
Suomedia

Should it be a screen shot or web file.......? You could see it on www.contiads.co.za/Entertainment main/ dating avenue / dating avenue sign up

its one of the forms of three i have the same problem with on the site.

You can attach a file using the paper clip icon you can see when replying to a post.


Matti Ressler
Suomedia

I attached the screen shot to word document hope you able use it.
I don't know if this will also be helpful to you but here is the url address:

http://www.contiads.co.za/Ezone/Dating%20Avenue/Dating%20Avenue%20sign%20up.htm

regards

Somebody please help me please please, i'm under a whole load stress and pressure do to this thing....... please help with this attachment problems

Its impossible without seeing your form - the link in your 3rd post is dead. The actual files would be much better.


Matti Ressler
Suomedia

datingavenue.php is the file we need to see.

Matti Ressler
Suomedia

HERE IS ALL THE CONTENT THAT IS IN THE DATINGAVENUE.PHP FILE.............................................HOPE ITS HELPFUL

<?php
$firstname = $_POST['FirstName'];
$lastname = $_POST['LastName'];
$day = $_POST['Day'];
$month = $_POST['Month'];
$year = $_POST['Year'];
$Gender = $_POST['Gender'];
$country = $_POST['country'];
$Province = $_POST['Province'];
$CityTown = $_POST['CityTown'];
$emailaddress = $_POST['EmailAddress'];

// Add file attachment to the message 
$message .= "--{$mime_boundary}\n" . 
"Content-Type: {$fileatt_type};\n" . 
" name=\"{$picture_name}\"\n" . 
"Content-Disposition: attachment;\n" . 
" filename=\"{$fileatt_name}\"\n" . 
"Content-Transfer-Encoding: base64\n\n" . 
$data . "\n\n" . 
"--{$mime_boundary}--\n"; 

$lookingfor = $_POST['LookingFor'];
$interestedin = $_POST['InterestedIn'];
$Duration = $_POST['Duration'];
$tnc_agree = $_POST['tnc_agree'];

$to = "ContiAds! <'datingavenue@contiads.co.za''mvity@yahoo.com'>";
$subject = "RE: New Dating Avenue SignUp!";
$body = "<html>".
"<head>".
"<title>Contact Request</title>".
"<style type='text/css'>".
"body,td,th {".
"font-family: Geneva, Arial, Helvetica, sans-serif;".
"font-size: 12px;".
"}".
".style1 {font-size: 24px}".
"</style></head>".
"<body>".
"<p align='center' class='style1'>ContiAds New Signup</p>".
"<table width='498' border='0' align='center' cellpadding='5' cellspacing='0'>".
"<tr>".
"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
"</tr>".
"<tr>".
"<td width='104' valign='top'>Full Name:</td>".
"<td width='374'>".$firstname." ".$lastname."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Date:</td>".
"<td>".$Date."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Month:</td>".
"<td>".$month."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Year:</td>".
"<td>".$year."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Gender:</td>".
"<td>".$Gender."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Country:</td>".
"<td>".$Country."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Province:</td>".
"<td>".$Province."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Email Address:</td>".
"<td>".$EmailAddress."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Looking For:</td>".
"<td>".$lookingfor."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Interested In:</td>".
"<td>".$InterestedIn."</td>".
"</tr>".
"<tr>".
"<td valign='top'>Duration:</td>".
"<td>".$Duration."</td>".
"</tr>".
"<tr>".
"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
"</tr>".
"</table>".
"</body>".
"</html>";

//Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
$headers .= 'From: ' . $email . "\r\n";
//$headers .= 'Cc: [email]myboss@example.com[/email]' . "\r\n";

if (mail($to, $subject, $body, $headers)) {
?>
<script language="javascript" type="text/javascript">
location.replace("Sign%20Up%20Success.htm");
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
location.replace("Sign%20Up%20Failure.htm");
</script>
<?php
}

?>

Sorry for the inconvienc i caused. Could you please show me how or give me an example how the brackets should be placed on the codes

Good day

I have attached the datingavenue.php file. i hope you can help me sort out the problem i'm having with uploading files.

regards

Something like this:

$path = '/home/suomedia/public_html/user_images/';  // the path to upload images (must be writable)
$filepath = $path . basename( $_FILES['Picture']['name']) ;
$len = strlen($_FILES['Picture']['name']) - 4;
$extension = substr($_FILES['Picture']['name'],$len);  // get the file extension
$permitted = array('.jpg', '.JPG', '.PNG', '.png', '.GIF', '.gif');  // only alow these file extensions
$success = false;
if (in_array($extension, $permitted)) {
  if(move_uploaded_file($_FILES['Picture']['tmp_name'], $filepath)) {
    $success = true;
    $fileatt_type = 'image/' . $extension;
    $picture_name = $_FILES['Picture']['name'];
    $file = fopen( $filepath, 'rb' ); 
    $data = fread( $file, filesize( $filepath ) ); 
    fclose( $file );
    $data = chunk_split( base64_encode( $data ) );
    $rand = md5( time() );  
    $mime_boundary = '==Multipart_Boundary_x{$rand}x';        
  } else {
    $success = false;
  }
} else {
  $success = false;
}
// Add file attachment to the message 
 $message .= "--{$mime_boundary}\n" . 
             "Content-Type: {$fileatt_type};\n" . 
             " name=\"{$picture_name}\"\n" . 
             "Content-Disposition: attachment;\n" . 
             " filename=\"{$picture_name}\"\n" . 
             "Content-Transfer-Encoding: base64\n\n" . 
             $data . "\n\n" . 
             "--{$mime_boundary}--\n";

$path must be a path on your server to a writable directory.

You also need to sanitize all user input from your form and decide what to do if $success = false.


Matti Ressler
Suomedia

Thanks alot

i got a couple of questions i would like to ask like:

1.what you meant by sanitize my input?

2.can i just put the code the way it is but change the path with the rest of the php?

3. Can i change the path and direct it to an email address and do i go about doing so ( an example would help )

4.if i have a number of uploaders in a form ( three maybe ) do i need to put the code three times.

Hope its not a problem with me asking alot of questions in order to understand a pit more?!!!!!!!!!!!!!!!!!!!!!!

regards

No problem you asking questions, thats what this forum is for. My apologies for being too busy to reply earlier - I tried to edit my last post but it would not let me.

Here is your file corrected:

<?php

$firstname = $_POST['FirstName'];
$lastname = $_POST['Lastname'];
$date = $_POST['Date'];
$month = $_POST['Months'];
$year = $_POST['Year'];
$Gender = $_POST['Gender'];
$country = $_POST['Country'];
$Province = $_POST['ProvinceStateRegion'];
$CityTown = $_POST['CityTown'];
$emailaddress = $_POST['EmailAddess'];
$lookingfor = $_POST['LookingFor'];
$interestedin = $_POST['InterestedIn'];
$Duration = $_POST['Duration'];
$tnc_agree = $_POST['tnc_agree'];
	
$to = "ContiAds! <you@your_domain.com>"; // put here the email address you want this sent to
$subject = "New ContiAds SignUp!";
$body = "<html>".
	"<head>".
	"<title>Contact Request</title>".
	"<style type='text/css'>".
	"body,td,th {".
		"font-family: Geneva, Arial, Helvetica, sans-serif;".
		"font-size: 12px;".
	"}".
	".style1 {font-size: 24px}".
	"</style></head>".
	"<body>".
	"<p align='center' class='style1'>ContiAds New Signup</p>".
	"<table width='498' border='0' align='center' cellpadding='5' cellspacing='0'>".
	  "<tr>".
		"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
	  "</tr>".
	  "<tr>".
		"<td width='104' valign='top'>Full Name:</td>".
		"<td width='374'>".$firstname." ".$lastname."</td>".
	 "</tr>".
	  "<tr>".
		"<td valign='top'>Date:</td>".
		"<td>".$date."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Month:</td>".
		"<td>".$month."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Year:</td>".
		"<td>".$year."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Gender:</td>".
		"<td>".$Gender."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Country:</td>".
		"<td>".$country."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Province:</td>".
		"<td>".$Province."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Email Address:</td>".
		"<td>".$emailaddress."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Looking For:</td>".
		"<td>".$lookingfor."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Interested In:</td>".
		"<td>".$interestedin."</td>".
	  "</tr>".
	  "<tr>".
		"<td valign='top'>Duration:</td>".
		"<td>".$Duration."</td>".
	  "</tr>".
	  "<tr>".
		"<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
	  "</tr>".
	"</table>".
	"</body>".
	"</html>";
	
//Always set content-type when sending HTML email
$rand = md5( time() );  
$mime_boundary = '==Multipart_Boundary_' . $rand;
$headers = "From: " . $emailaddress . "\n" .
"Reply-To:" . $emailaddress . "\n" .
"MIME-Version: 1.0\n" . 
"Content-Type: multipart/mixed; boundary=\"" . $mime_boundary . "\"";
"\n\n";	

 $message = "This is a multi-part message in MIME format.\n\n" . 
                "--" . $mime_boundary . "\n" . 
                "Content-Type: text/html; charset=\"iso-8859-1\"\n" . 
                "Content-Transfer-Encoding: 7bit\n\n" .
                $body . "\n\n";
// Add file attachment to the message 

$path = '/home/suomedia/public_html/images/';  // the path to upload images (must be writable)
$filepath = $path . basename( $_FILES['Picture']['name']);
$len = strlen($_FILES['Picture']['name']) - 4;
$extension = substr($_FILES['Picture']['name'],$len);  // get the file extension
$permitted = array('.jpg', '.JPG', '.PNG', '.png', '.GIF', '.gif');  // only allow these file extensions
$success = false;
if (in_array($extension, $permitted)) {
  if(move_uploaded_file($_FILES['Picture']['tmp_name'], $filepath)) {
    $success = true;
    $fileatt_type = 'image/' . strtoupper(ltrim($extension, '.'));
    $picture_name = $_FILES['Picture']['name'];
    $file = fopen( $filepath, 'rb' ); 
    $data = fread( $file, filesize( $filepath ) ); 
    fclose( $file );
    $data = chunk_split( base64_encode( $data ) );
    $message .= "--" . $mime_boundary . "\n" . 
             "Content-Type: \"" . $fileatt_type . "\";\n" . 
             " name=\"" . $picture_name . "\"\n" . 
             "Content-Disposition: attachment;\n" . 
             " filename=\"" . $picture_name . "\"\n" . 
             "Content-Transfer-Encoding: base64\n\n" . 
             $data . "\n\n" . 
             "--" . $mime_boundary . "--\n";            
  } else {
    $success = false;
  }
} else {
  $success = false;
}                

// end file attachment

if($success == true) {
if (mail($to, $subject, $message, $headers)) {
?>
<script language="javascript" type="text/javascript">
	location.replace("Sign%20Up%20Success.htm");
</script>
<?php
} else {
?>
<script language="javascript" type="text/javascript">
	location.replace("Sign%20Up%20Failure.htm");
</script>
<?php
}
} else {
?>
<script language="javascript" type="text/javascript">
	location.replace("Sign%20Up%20Failure.htm");
</script>
<?php
}
?>

$path must be set to a file system path on your server where you want the images uploaded. The directory must have 777 permissions (writeable).

You should also try to follow the coding conventions in the above code, particularly when $variables are used within text content. You should also be aware that variables are case sensitive (including $_POST variables). It is good practice to keep all of these lower case (I have not corrected yours other than where you had upper case in one place and lower case elsewhere (please check your other file also). Put your correct email address above where I have left a comment.

Sanitizing user input means stripping the posted data from anything that may be malicious, eg. you email is sent in HTML format - I could quite easily post a malicious script to you that would execute when you open the email. Search Google for input filtering.

Yes, you need to add the file handling each time you add an attachment.


Matti Ressler
Suomedia

Na its all good, you also probably have a personal life you need to attend to.

I would like ask something, how do you go about sanitizing.... I'm not familiar with it ?!

Regards

Sanitizing user input means stripping the posted data from anything that may be malicious

You can use mysql_real_escape_string for the user input or addslashes.

How do i link the attachment script with the up loader on the form....... Where i place the uploader name on the script ?

You should use the entire code I posted in my last post as datingavenue.php (replace the file). In your form you already have:

<form method="POST" action="datingavenue.php"

That is all that is needed. You already have the variable "Picture" in your form and you can see it in my code as:

$_FILES['Picture']['name']

Please make adjustment to your new datingavenue.php where I indicated above (you must have the correct file system path to your images upload directory and its permissions need to be set to 777 - writable).


Matti Ressler
Suomedia

i published the site again with the new script but i get an error message that displays as follows

Parse error: syntax error, unexpected $end in /usr/home/conti634/public_html//Dating 20Avenue/Dating 20Avenue 20sign 20up.htm on line 156

I also applied the the same attachment to my other scripts and also experience the same problem.
what could be the problem

You have a missing closing curly bracket } in your code.


Matti Ressler
Suomedia

Indent your code, find an unclosed brace { and close it.

Okay. Which means i cancel the ?> at the end because thats what gives the error even when i copy the script you ultered for me ( thanks again for that ). Will the script still function if i don't end with ?>

I closed all the brackets but still have the same problem ( it says unexpected end once again ) what could be the problem. PLEASE HELP

Please use the attachment option (the paper clip) and attach a zip of your files to your next post.


Matti Ressler
Suomedia

hey there. i have attached the files in a zip folder called php files. Hope you can pick up my mistakes

In each of the files that have the error (3 in the attachment) add a closing curly bracket } before the very last ?> in each file.

With your $path variable, it MUST be a full file system path, eg. /home/suomedia/public_html/upload/ or use:

$_SERVER['DOCUMENT_ROOT'] . '/uploads/'

Also, you are far better to use a PHP redirect than javascript:

<?php
header("location: success.htm");
?>

Matti Ressler
Suomedia

The full file system is the way the folders are structured in the site ?

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.