Jump to content

Email Attachment Script Not Working.


TheScripter

Recommended Posts

http://independentrepublicofursum.tk/Become_a_Citizen/ is the page I am having trouble on. Basically what I want to happen here is for the user to download a fillable pdf application, fill it, and upload it. From there the php script will send it to my email so I can review it. My code is...

 



function mail_file($to, $from, $subject, $body, $file) {

$boundary = md5(rand());
$header = array(

"MIME-Version: 1.0",
"Content-Type: multipart/mixed; boundary=\"{$boundary}\"",
"From: {$from}"

);

$message = array(

"--{$boundary}",
"Content-Type: text/plain",
"Content-Transfer-Encoding: 7bit",
'',
chunk_split($body),
"--{$Boundary}",
"Content-Type: {$file['type']}; name=\"{$file['name']}\"",
"Content-Disposition: attachment; filename=\"{$file['name']}\"",
"Content-Transfer-Encoding: base64",
'',
chunk_split(base64_encode(file_get_contents($file['tmp_name']))),
"--{$boundary}--"

);

mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));

}

 

Then to send it I use...

 



if (isset($_FILES['file'])) {

mail_file('[email protected]', '[email protected]', 'test subject', '', $_FILES['file']);

}

 

My form is...

 



<form name="citizenship_application" action="" method="post" enctype="multipart/form-data">

First Name: <input type="text" name="first_name" value="<?php echo $first_name_value; ?>">

<br />
<br />

Last Name: <input type="text" name="last_name" value="<?php echo $last_name_value; ?>">

<br />
<br />

E-Mail:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="text" name="e_mail" value="<?php echo $e_mail_value; ?>">

<br />
<br />

Gender:&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp<input type="radio" name="sex" value="male" <?php echo $male_pre_select; ?> >Male

<input type="radio" name="sex" value="female" <?php echo $female_pre_select; ?> >Female

<br />
<br />

<label for="file">Please specify your application file:</label>

<br />

                                                       <input type="hidden" name="MAX_FILE_SIZE" value="501">
<input type="file" name="file" size="50">

<br />
<br />

<input type="submit" value="Submit Application" name="submit"> &nbsp<?php echo $error; ?>

</form>

 

I get two errors, the first one is...

 

Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/u418744221/public_html/B­ecome_a_Citizen/index.php on line 38

 

Line 38 is...

 

chunk_split(base64_encode(fil­e_get_contents($file['tmp_name­']))),

 

My second error is...

 

 

Warning: implode() [function.implode]: Invalid arguments passed in /home/u418744221/public_html/B­ecome_a_Citizen/index.php on line 43

 

line 43 is...

 

mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));

 

 

 

Really need this finished, ASAP. I can't figure it out, any help appreciated thanks ya'll.

Link to comment
https://forums.phpfreaks.com/topic/268941-email-attachment-script-not-working/
Share on other sites

Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/u418744221/public_html/B­ecome_a_Citizen/index.php on line 38

 

Line 38 is...

 

chunk_split(base64_encode(fil­e_get_contents($file['tmp_name­']))),

 

That would mean that $_FILES['tmp_name'] is empty; which would imply that the upload failed. You really should check that ['error'] is zero (or UPLOAD_ERR_OK) before you assume that a file was actually and successfully uploaded.

 

Suggested reading: PHP Manual - Handling File Uploads

 

 

Warning: implode() [function.implode]: Invalid arguments passed in /home/u418744221/public_html/B­ecome_a_Citizen/index.php on line 43

 

line 43 is...

 

mail($to, $subject, implode("\r\n", $message), implode("\r\n", $headers));

 

The variable $headers does not exist in that code

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.