Current location: Hot Scripts Forums » Programming Languages » PHP » Can only send either form or attachment. Not both :-(


Can only send either form or attachment. Not both :-(

Reply
  #1 (permalink)  
Old 05-26-05, 01:14 PM
look4edmund look4edmund is offline
Newbie Coder
 
Join Date: May 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Can only send either form or attachment. Not both :-(

Hi,

I've done up a simple page. problem is when i submit form, if there's no attachment, I'll receive the drag down items. But when i have drag down items and attachment, i only receive attachment.

Please help to see what's wrong with code. Thanks.

<form action="../r2_form.php" name="form2" method="post" enctype="multipart/form-data">
<select name="Availability" class="style10">
<option value="" selected>---------- Please Select Job ----------</option>
<option value="Immediate">Immediate</option>
<option value="1 Week">1 Week</option>
<option value="2 Week">2 Week</option>
<option value="3 Week">3 Week</option>
<option value="1 Month">1 Month</option>
<option value="6 Week">6 Week</option>
<option value="2 Week">2 Month</option>
<option value="3 Month">3 Month</option>
</select>
</span></textarea>
</span></td>
</tr>
<tr class="style10">
<td colspan="2" align="center"><span class="style54"><strong><span class="style49">Attach Resume</span><img src="images/spacer.gif" width="15" height="1"> </strong></span>
<input type="file" name="attachment" /></td>
</tr>
<tr class="style10">
<td colspan="2" align="center"><span class="style48">
<input type="submit" value="Upload Resume or Data">
</span></td>
</tr>
<tr class="style10">
<td colspan="2" align="center"> </td>
</tr>
</table>
</form>



Action file...... r2_form.php

<?
$admin = ("look4edmund@gmail.com");
$sitename = ("gmail.com");

$FName = $_POST['FName'];
$LName = $_POST['LName'];

$Availability = $_POST['Availability'];

$submissiondate = date("D dS M, Y h:i a");

$filename= "counter.txt" ; // Numbers the submissions of the form
$fd = fopen ($filename , "r") or die ("Can't open $filename") ;
$fstring = fread ($fd , filesize ($filename)) ;
fclose($fd) ;

$fd = fopen ($filename , "w") or die ("Can't open $filename") ;
$fcounted = $fstring + 1 ;
$fout = fwrite ($fd , $fcounted ) ;
fclose($fd) ;

$subject = "$sitename Submission No. $fcounted\n";
$mail_boundary = "x".md5(time())."x";
$header = "From: $name <$email>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: multipart/mixed; boundary=\"{$mail_boundary}\"\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-MSMail-Priority: Normal\r\n";
$header .= "X-Mailer: aMAILzing 0.9 http://scripts.inexistent.org\r\n";
$header .= "This is a multi-part message in MIME format.\r\n\r\n";
$header .= "--{$mail_boundary}\r\n";
$header .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$header .= "Date: ".date(R)."\r\n";
$header .= "Content-Transfer-Encoding:7bit\r\n\r\n";
$header .= $message."\r\n\r\n";

$msg .= "----- Website Submission -----\n\n";
$msg .= "Date/Time Submitted: $submissiondate - EST\n";
$msg .= "Name: $FName $LName\n";
$msg .= "Submission ID: $fcounted\n\n";
$msg .= "Availability: $Availability \n\n";
$msg .= "Message:\n\n";


// Attach the uploaded files, if there is any.

if($_FILES){

if (get_magic_quotes_runtime() == 1){
set_magic_quotes_runtime(0);
}

foreach($_FILES as $key=>$value){

foreach($value as $key2 => $value2){
$$key2 = $value2;
}

if (is_uploaded_file($tmp_name)) {
$fp = fopen($tmp_name,'rb');
$read = fread($fp,$size);
fclose($fp);

$file = base64_encode($read);
$file = chunk_split($file);

$header .= "--$mail_boundary\r\n";
$header .= "Content-type: $type; name=\"$name\"\r\n";
$header .= "Content-Transfer-Encoding:base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"$name\"\r\n\r\n";
$header .= $file."\r\n\r\n";
}
}
}

$to = "$admin";

mail($to, $subject, $msg, $header, $mailheaders);



?>
Reply With Quote
  #2 (permalink)  
Old 05-26-05, 01:16 PM
look4edmund look4edmund is offline
Newbie Coder
 
Join Date: May 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Any kind soul can help?

This is not database driven.

Basically what i want is just for people to submit their resume and click when they can start work. All the information (form data & attachment) is just send via email.




Pls help. Thanks.
Reply With Quote
  #3 (permalink)  
Old 05-26-05, 08:37 PM
look4edmund look4edmund is offline
Newbie Coder
 
Join Date: May 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Please help anybody...
Reply With Quote
  #4 (permalink)  
Old 05-26-05, 11:44 PM
shroder shroder is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
I think you had the header and message mixed up a little.

I basically moved everything below "This is a multi-part message in MIME format", which was the message content, into $msg and moved the file data into $msg as well.

Here's a snippet of the code I changed:

Code:
$subject = "$sitename Submission No. $fcounted\n";
$mail_boundary = "x".md5(time())."x";
$header = "From: $name <$email>\r\n";
$header .= "MIME-Version: 1.0\r\n";
$header .= "Content-type: multipart/mixed; boundary=\"{$mail_boundary}\"\r\n";
$header .= "X-Priority: 3\r\n";
$header .= "X-MSMail-Priority: Normal\r\n";
$header .= "X-Mailer: aMAILzing 0.9 http://scripts.inexistent.org\r\n";
$header .= "This is a multi-part message in MIME format.\r\n\r\n";


$msg = "--{$mail_boundary}\r\n";
$msg .= "Content-type: text/plain; charset=\"iso-8859-1\"\r\n";
$msg .= "Date: ".date(R)."\r\n";
$msg .= "Content-Transfer-Encoding:7bit\r\n\r\n";
$msg .= "----- Website Submission -----\n\n";
$msg .= "Date/Time Submitted: $submissiondate - EST\n";
$msg .= "Name: $FName $LName\n";
$msg .= "Submission ID: $fcounted\n\n";
$msg .= "Availability: $Availability \n\n";
$msg .= "Message:\n\n";




// Attach the uploaded files, if there is any.

if($_FILES){

	if (get_magic_quotes_runtime() == 1){
		set_magic_quotes_runtime(0);
	}

	foreach($_FILES as $key=>$value){
		foreach($value as $key2 => $value2){
			$$key2 = $value2;
		}

		if (is_uploaded_file($tmp_name)) {
			$fp = fopen($tmp_name,'rb');
			$read = fread($fp,$size);
			fclose($fp);

			$file = base64_encode($read);
			$file = chunk_split($file);
			$msg .= "--$mail_boundary\r\n";
			$msg .= "Content-type: $type; name=\"$name\"\r\n";
			$msg .= "Content-Transfer-Encoding:base64\r\n";
			$msg .= "Content-Disposition: attachment; filename=\"$name\"\r\n\r\n";
			$msg .= $file."\r\n\r\n";
		}
	}
}
If you can't get that to work for some reason let me know and I'll send you the file I modified.
Reply With Quote
  #5 (permalink)  
Old 05-27-05, 02:01 AM
Jaffizzle Jaffizzle is offline
Newbie Coder
 
Join Date: May 2005
Posts: 61
Thanks: 0
Thanked 0 Times in 0 Posts
PHP Code:

$mail_boundary "x".md5(time())."x";

$header "From: $name <$email>\r\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-Type: multipart/mixed; boundary=\"{$mail_boundary}\"\n";
$header .= "X-Priority: 3\n";
$header .= "X-MSMail-Priority: Normal\n";
$header .= "X-Mailer: aMAILzing 0.9 http://scripts.inexistent.org\n";
$header .= "This is a multi-part message in MIME format.\n\n";


$header .= "--{$mail_boundary}\n";
$header .= "Content-Type: text/plain; charset=\"iso-8859-1\"\n";
$header .= "Content-Transfer-Encoding:binary\n\n";
$header .= "--{$mail_boundary}\n";
$header .= "----Website Submission----\n\n";
$header .= "Date/Time Submitted: $submissiondate - EST\n";
$header .= "Name: $FName $LName\n";
$header .= "Submission ID: $fcounted\n\n";
$header .= "Availability: $Availability \n\n";
$header .= "Message:\n\n";




// Attach the uploaded files, if there is any.

if($_FILES){

    if (
get_magic_quotes_runtime() == 1){
        
set_magic_quotes_runtime(0);
    }

    foreach(
$_FILES as $key=>$value){
        foreach(
$value as $key2 => $value2){
            $
$key2 $value2;
        }

        if (
is_uploaded_file($tmp_name)) {
            
$fp fopen($tmp_name,'rb');
            
$read fread($fp,$size);
            
fclose($fp);

            
$file base64_encode($read);
            
$file chunk_split($file);
            
$header .= "--{$mail_boundary}\n";
            
$header .= "Content-Type: $type; name=\"$name\"\n";
            
$header .= "Content-Transfer-Encoding:base64\n";
            
$header .= "Content-Disposition: attachment; filename=\"$name\"\n\n";
            
$header .= $file."\n\n";
        }
    }}

mail($to$subject'huh'$header); 
heres my way, good luck
Reply With Quote
  #6 (permalink)  
Old 05-27-05, 04:58 AM
look4edmund look4edmund is offline
Newbie Coder
 
Join Date: May 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up God Bless ;-)

Hi Guys...

You guys are wonderful...let me check on it...
Really appreciate it!!!

Thanks and thanks again!!!
Reply With Quote
  #7 (permalink)  
Old 05-27-05, 05:49 AM
look4edmund look4edmund is offline
Newbie Coder
 
Join Date: May 2005
Posts: 8
Thanks: 0
Thanked 0 Times in 0 Posts
Thumbs up Bravo...Shroder perfecto 10 points...

Shroder...your code is perfect 10 points. Works out fine.

Jaffizle 9 points cos message becomes attached txt.




Thanks guys. Means a lot to me. ;-)
Reply With Quote
Reply

Bookmarks


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

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
formmail problem gscraper Perl 12 08-27-04 03:06 AM
Send form results to multiple databases stomlin PHP 3 08-18-04 12:14 PM
E-Mail form / Send code on one page perleo PHP 4 02-11-04 01:16 AM
send email when sending form (asp) bmatth1 Script Requests 0 09-30-03 05:52 AM


All times are GMT -5. The time now is 06:46 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.