User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 373,096 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 3,946 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 1773 | Replies: 48
Reply
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: Serious problem with attchments-please help

  #11  
Mar 20th, 2008
datingavenue.php is the file we need to see.



Matti Ressler
Suomedia
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #12  
Mar 20th, 2008
HERE IS ALL THE CONTENT THAT IS IN THE DATINGAVENUE.PHP FILE.............................................HOPE ITS HELPFUL

  1. <?php
  2. $firstname = $_POST['FirstName'];
  3. $lastname = $_POST['LastName'];
  4. $day = $_POST['Day'];
  5. $month = $_POST['Month'];
  6. $year = $_POST['Year'];
  7. $Gender = $_POST['Gender'];
  8. $country = $_POST['country'];
  9. $Province = $_POST['Province'];
  10. $CityTown = $_POST['CityTown'];
  11. $emailaddress = $_POST['EmailAddress'];
  12.  
  13. // Add file attachment to the message
  14. $message .= "--{$mime_boundary}\n" .
  15. "Content-Type: {$fileatt_type};\n" .
  16. " name=\"{$picture_name}\"\n" .
  17. "Content-Disposition: attachment;\n" .
  18. " filename=\"{$fileatt_name}\"\n" .
  19. "Content-Transfer-Encoding: base64\n\n" .
  20. $data . "\n\n" .
  21. "--{$mime_boundary}--\n";
  22.  
  23. $lookingfor = $_POST['LookingFor'];
  24. $interestedin = $_POST['InterestedIn'];
  25. $Duration = $_POST['Duration'];
  26. $tnc_agree = $_POST['tnc_agree'];
  27.  
  28. $to = "ContiAds! <'datingavenue@contiads.co.za''mvity@yahoo.com'>";
  29. $subject = "RE: New Dating Avenue SignUp!";
  30. $body = "<html>".
  31. "<head>".
  32. "<title>Contact Request</title>".
  33. "<style type='text/css'>".
  34. "body,td,th {".
  35. "font-family: Geneva, Arial, Helvetica, sans-serif;".
  36. "font-size: 12px;".
  37. "}".
  38. ".style1 {font-size: 24px}".
  39. "</style></head>".
  40. "<body>".
  41. "<p align='center' class='style1'>ContiAds New Signup</p>".
  42. "<table width='498' border='0' align='center' cellpadding='5' cellspacing='0'>".
  43. "<tr>".
  44. "<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
  45. "</tr>".
  46. "<tr>".
  47. "<td width='104' valign='top'>Full Name:</td>".
  48. "<td width='374'>".$firstname." ".$lastname."</td>".
  49. "</tr>".
  50. "<tr>".
  51. "<td valign='top'>Date:</td>".
  52. "<td>".$Date."</td>".
  53. "</tr>".
  54. "<tr>".
  55. "<td valign='top'>Month:</td>".
  56. "<td>".$month."</td>".
  57. "</tr>".
  58. "<tr>".
  59. "<td valign='top'>Year:</td>".
  60. "<td>".$year."</td>".
  61. "</tr>".
  62. "<tr>".
  63. "<td valign='top'>Gender:</td>".
  64. "<td>".$Gender."</td>".
  65. "</tr>".
  66. "<tr>".
  67. "<td valign='top'>Country:</td>".
  68. "<td>".$Country."</td>".
  69. "</tr>".
  70. "<tr>".
  71. "<td valign='top'>Province:</td>".
  72. "<td>".$Province."</td>".
  73. "</tr>".
  74. "<tr>".
  75. "<td valign='top'>Email Address:</td>".
  76. "<td>".$EmailAddress."</td>".
  77. "</tr>".
  78. "<tr>".
  79. "<td valign='top'>Looking For:</td>".
  80. "<td>".$lookingfor."</td>".
  81. "</tr>".
  82. "<tr>".
  83. "<td valign='top'>Interested In:</td>".
  84. "<td>".$InterestedIn."</td>".
  85. "</tr>".
  86. "<tr>".
  87. "<td valign='top'>Duration:</td>".
  88. "<td>".$Duration."</td>".
  89. "</tr>".
  90. "<tr>".
  91. "<td colspan='2' valign='top' bgcolor='#333333' height='2px'></td>".
  92. "</tr>".
  93. "</table>".
  94. "</body>".
  95. "</html>";
  96.  
  97. //Always set content-type when sending HTML email
  98. $headers = "MIME-Version: 1.0" . "\r\n";
  99. $headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
  100. $headers .= 'From: ' . $email . "\r\n";
  101. //$headers .= 'Cc: [email]myboss@example.com[/email]' . "\r\n";
  102.  
  103. if (mail($to, $subject, $body, $headers)) {
  104. ?>
  105. <script language="javascript" type="text/javascript">
  106. location.replace("Sign%20Up%20Success.htm");
  107. </script>
  108. <?php
  109. } else {
  110. ?>
  111. <script language="javascript" type="text/javascript">
  112. location.replace("Sign%20Up%20Failure.htm");
  113. </script>
  114. <?php
  115. }
  116.  
  117. ?>
Last edited by MattEvans : Mar 20th, 2008 at 3:36 pm. Reason: Added code tags.
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #13  
Mar 20th, 2008
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
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #14  
Mar 25th, 2008
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
Attached Files
File Type: php datingavenue.php (3.2 KB, 1 views)
Reply With Quote  
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: Serious problem with attchments-please help

  #15  
Mar 25th, 2008
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
Last edited by Suomedia : Mar 25th, 2008 at 12:29 pm.
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #16  
Mar 25th, 2008
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
Reply With Quote  
Join Date: Mar 2008
Posts: 153
Reputation: Suomedia is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 19
Suomedia Suomedia is offline Offline
Junior Poster

Re: Serious problem with attchments-please help

  #17  
Mar 26th, 2008
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
Last edited by Suomedia : Mar 26th, 2008 at 1:49 pm.
If you want your dreams to come true, the first thing you must do is to wake up....
Suomedia - Dynamic Content Management
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #18  
Mar 27th, 2008
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
Reply With Quote  
Join Date: Nov 2007
Location: Bangalore, India
Posts: 3,024
Reputation: nav33n has a spectacular aura about nav33n has a spectacular aura about 
Rep Power: 8
Solved Threads: 227
nav33n's Avatar
nav33n nav33n is online now Online
Posting Sensei

Re: Serious problem with attchments-please help

  #19  
Mar 27th, 2008
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.
Programming today is a race between software engineers striving to build bigger and better idiot-proof programs, and the Universe trying to produce bigger and better idiots. So far, the Universe is winning.

*PM asking for help will be ignored*
Reply With Quote  
Join Date: Mar 2008
Posts: 26
Reputation: Vity is an unknown quantity at this point 
Rep Power: 1
Solved Threads: 0
Vity Vity is offline Offline
Light Poster

Re: Serious problem with attchments-please help

  #20  
Mar 27th, 2008
How do i link the attachment script with the up loader on the form....... Where i place the uploader name on the script ?
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb PHP Marketplace
Thread Tools Display Modes

Other Threads in the PHP Forum

All times are GMT -4. The time now is 4:53 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC