I have a simple contact form that allows me to send attachments but I'm having trouble sending the right file
Can anyone help me out?
This is the code
http://pastebin.com/qtGyJdjD
Email attachments
-
- Posts: 205
- Joined: Mon Jul 09, 2012 11:13 pm
Re: Email attachments
Other than there being no variables called $filename and $fileContent?
<?php while(!$succeed = try()); ?>
Re: Email attachments
I'm nearly done with this but curiously this is putting my body(message) inside the file that i'm uploading (in this case an image) thus making it inaccessible.
http://pastebin.com/AkbLcMsi
@ExtremeGaming i was writting my message whe you replied.
http://pastebin.com/AkbLcMsi
@ExtremeGaming i was writting my message whe you replied.
Re: Email attachments
Why are you using pastebin? You can put the code in the code tags
Re: Email attachments
I used pastebin for another forum and just copied and pasted
I haven't figured it out :S
I haven't figured it out :S
Re: Email attachments
I would just upload the file to the server and put a link in the email somewhere.
Much easier
Much easier
Re: Email attachments
easy != fun but it does equals no headaches xD
I want to figure how to do this that way
I want to figure how to do this that way
Re: Email attachments
I just found out like 2 minutes ago that Jacek has a How ro send email attachments tutorial :S
Re: Email attachments
I've applied Jacek's tutorial to what I have and this is the final result
If I send a jpg or a pdf file they send fine and If I send a php file for instance it doesn't show a thing. It simply shows a "noname" file.
What I need to do next, after fixing this, is to make a little verification for file types and do a size limit verification.
I also need to find a way to if the user doesn't want to send any attachment it just sends the mail without any problem. Now its gving me a Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/a3876128/public_html/testcontact.php on line 41
<?php if(empty($_POST) === false){ $errors = array(); $name = $_POST['name']; $email = $_POST['email']; $message = $_POST['message']; $file = $_FILES['filename']; if(empty($name) === true || empty($email) === true || empty($message) === true){ $errors[] = 'Name, email and message are required!'; } else { if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){ $errors[] ='Not a valid email'; } if(ctype_alpha($name) === false){ $errors[] ='Name must only contain letters'; } } if(empty($errors) === true){ $boundary = md5(rand()); $headers = array( 'MIME-Version: 1.0', "Content-type: multipart/mixed; boundary=\"{$boundary}\"", "From: {$email}" ); $message = array( "--{$boundary}", 'Content-type: text/html', 'Content-Transfer-Encoding: 7bit', '', chunk_split($message), "--{$boundary}", "Content-type: {$file['type']}; name=\"{$file['filename']}\"", "Content-Disposition: attachment; filename=\"{$file['filename']}\"", 'Content-Transfer-Encoding: base64', '', chunk_split(base64_encode(file_get_contents($file['tmp_name']))), "--{$boundary}--" ); //send email mail($email, 'Contact form', implode("\r\n", $message), implode("\r\n", $headers)); //redirect user header('Location: index.php?sent'); exit(); } } ?>but i'm having a problem. I need to get the name of the file and the extension to send the to the user.
If I send a jpg or a pdf file they send fine and If I send a php file for instance it doesn't show a thing. It simply shows a "noname" file.
What I need to do next, after fixing this, is to make a little verification for file types and do a size limit verification.
I also need to find a way to if the user doesn't want to send any attachment it just sends the mail without any problem. Now its gving me a Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/a3876128/public_html/testcontact.php on line 41
Re: Email attachments
Thanks everybody but I already have the problem solved