@Szegi87 you have some off characters on line 30, you have Mime instead of MIME. And your $extension var is in all quotes, but thats PHP you have inside of there?
@Szegi87 Thats because you didn't move the uploaded file to your computer first. You need to use move_file_upload first, then use that location as the file
I'm getting the same error as Rygap, and I'm also a windows user. $replyto is never defined, and I changed it to $to even though I never saw this guy change it. Perhaps linux does treat things differently and you can't just use windows with a local email server with this code.
Thank you so much for the code! I was looking for one that worked for sometime. Please make all the code available on your website or blog. It will save some people a lot of headaches and problems !
Under the comments //standard mail headers You use a variable named - $replyto - that is not declared anywhere. I imagine that it is just a typo, but I didnt see it corrected. Anyway, what would we use there instead $to or $from ?
For windows users try downloading PostCastServer it works pretty decent
Hey optikalefxx - thanks for this video. It works really well and is just what I wanted. I did have one question though: how can you get it to upload the file to a folder on the server once it has been sent (in case it needs to be redownloaded)? I have tried and can get it to up load with the if(move_uploaded_file($_FILES['attachment']['tmp_name'], $target)), but I can get it to send the mail. I can get it to send the mail but not upload to server. Do you have any suggestions on how to do this?
hey man, thanks for the video. it works great with gmail but i can't get it to work with hotmail or yahoo mail, could you please help me with this. any help would be greatly appreciated. THANKS IN ADVANCE
@molnarcsilla just separate each file by the attachment boundry. i wanna do a video on this soon, so if you can't figure it out persay - keep an eye out for that video.
@chaseranster85858 don't use godaddy - get a better host provider. OR, call godaddy because I know it does work with them. You probably aren't paying them enough.
hey so I'm sry to say but I'm another person with a problem! lol
but any ways I'm constantly getting the please enter the right file type message even when I attach the right file type! I have checked my code and all seams right?!?! any ideas? thank u in advanced
Hey, I know you must be really busy with all that you do. But I could really use your help with this form. I'm receiving the same error as "lingachannel" (2 months ago):
Warning: file_get_contents(...) [function.file-get-contents]: failed to open stream: No such file or directory in /home/...thank_you.php on line 205
The email sends and I receive an attachment, but it's always 0kb and can never be accessed. Would you be able to help me with this?
hi, thanks a lot for the code. It work great..!!! but i have just one problem. The attachment arrives to my mailbox like text. Just text... if a send a PDF file, i got a TEXT like this "JVBERi0xLjMNJf////8NMSAwIG9iag08PA0vVGl0bGUgKP7/AGQAbwBjAHUAbQBlAG4AdCkNL1Byb2R1Y2VyIChBbXl1bmkgUERGIENvbnZlcn".
Great video. Having trouble with the code, the attachments are not being decode, and show as 0kb in the email. Sure it's something simple. Could I send you my code, or could you supply a working copy.
Now, I had a little bit a problems with some parts of the code because I tried to accommodate some part of it to suite my needs and to see how it works.
I noticed 2 things:
- If I use (') - as a quotation marks inside of (") it will nor work. It only works with (\"). Usually in PHP when I work with HTML it does not matter.
- In some parts of the code it is OBLIGATORY to put double new lines/paragraphs like this: "\r\n\r\n". Otherwise it will not work again.
@kristijanmne I though that it should be useful also to put this to on comments even if I only can guess why is it happening.
Another thing that I wanted to ask is this:
"Content-Transfer-Encoding: 7bit" - it is ok to put it for "Content-type: text/html" and is there any thing that I or others should know about this when I send mails in "charset=utf-8"?
I did exactly as you done, but am getting an empty file (0 kb size). I saw also your second video with the error example, i checked every letter in my file but find nothing.
Am getting this error:
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/.................. /sendfile.php on line 30
How should I modify the code when I want to be able to send the email either with attachment or without. Because when I try without it obviously writes me No attachement.
@qwertzpoi you need to first get rid of the 'if else' check for the file being posted. The !emtpy($_FILES['attachment']['name'] bit
and then you need to kill the attachment "part" basically the code underneath of the comment // file attachment. Cuz with no attachment you don't want to send those headers.
Thanks a lot! After wathcing your movie and lots of swearing, I finally made it and actually started to understand what I was doing.
Tip for attachments: I found out that my Ubuntu Server limited my file attachment size to 2 MB. You have to edit the php.ini file and edit the line "upload_max_filesize =2MB"
Man, thats was amazing. I need some help to finally make my php work. Would you be willing to have a look at it and then we can talk about how much you would charge?
What am I doing wrong? I cannot get this script to work for me. I have entered the necessary info into the spaces provided yet I cannot get the form to work. Any suggestions?
What I mean is, instead of just getting the last 4 you could do something like this:
$dot_index = stripos($base, ".");
$extension = substr($base, $dot_index);
That will return the extension and then you can just compare it to all the elements in the allowed extension array and not have to worry about hard-coding the extension length.
@warlord90210 i thought about that. But you would need to get the LAST index of "." because we can't gurantee there is only 1 dot. so i figured it was safer to get the end, because we can gurantee the end is the extension
Great video, could you instead check for the length of the array for the different types allowed and then you wouldn't have to keep a constant 4 for the length?
Fantastic Job........
nidajaved139 1 week ago in playlist PHP Tuts
Wasting of my time
why you did not Attached the source file :(
azizjamali 2 months ago
great vid, great tutorial... got it workin on my system thanks to you.
WikiPeoples 4 months ago
Question, is it possible to send an attachment to someone that can't be forwarded to someone else?
dbmrhi 5 months ago
@dbmrhi nope sorry
optikalefxx 5 months ago
THankss man!!
MrJavap 5 months ago
God bless you man!
sulitrwsky2 6 months ago
whats wrong with this code pastebin com/tddssFpA
Szegi87 7 months ago
@Szegi87 you have some off characters on line 30, you have Mime instead of MIME. And your $extension var is in all quotes, but thats PHP you have inside of there?
optikalefxx 7 months ago
@optikalefxx ii sends email but filename is always something like that "/tmp/phpGst0z8" and the size is 0kb
Szegi87 7 months ago
@Szegi87 Thats because you didn't move the uploaded file to your computer first. You need to use move_file_upload first, then use that location as the file
optikalefxx 7 months ago
@optikalefxx is there another way? i mean just send email with attachment without putting it on my hosting server?
Szegi87 7 months ago
@Szegi87 just do unlink($file) afterwards
optikalefxx 7 months ago
I'm getting the same error as Rygap, and I'm also a windows user. $replyto is never defined, and I changed it to $to even though I never saw this guy change it. Perhaps linux does treat things differently and you can't just use windows with a local email server with this code.
obesechicken13 8 months ago
@obesechicken13 Also, it'd be nice to actually put the source code up somewhere.
obesechicken13 8 months ago
Thank you so much for the code! I was looking for one that worked for sometime. Please make all the code available on your website or blog. It will save some people a lot of headaches and problems !
RavanaMad 8 months ago in playlist PHP
If I try to use this script with .mp3 attachments it cuts the track length down to 7 seconds. Any idea why?
RiseandShineNetwork 8 months ago
after posting the form with the php script on one page I get this resolt on the attach.php page:
Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/d/e/d/dedwards727/html/attach.php on line 140
fail. looking forward to your help. Thanks in advance.
marketerpaul 9 months ago
after posting the form with the php script on ane page I get this resolt on the attach.php page:
Warning: mail() [function.mail]: Bad parameters to mail() function, mail not sent. in /home/content/d/e/d/dedwards727/html/attach.php on line 140
fail. looking forward to your help. Thanks in advance.
marketerpaul 9 months ago
Under the comments //standard mail headers You use a variable named - $replyto - that is not declared anywhere. I imagine that it is just a typo, but I didnt see it corrected. Anyway, what would we use there instead $to or $from ?
For windows users try downloading PostCastServer it works pretty decent
Rygap 9 months ago
Can anyone help, The Code did not work? for me
freetattle 9 months ago
Hey optikalefxx - thanks for this video. It works really well and is just what I wanted. I did have one question though: how can you get it to upload the file to a folder on the server once it has been sent (in case it needs to be redownloaded)? I have tried and can get it to up load with the if(move_uploaded_file($_FILES['attachment']['tmp_name'], $target)), but I can get it to send the mail. I can get it to send the mail but not upload to server. Do you have any suggestions on how to do this?
flattley 9 months ago
i cannot thank you enough.
DanMustoe 10 months ago
hey man, thanks for the video. it works great with gmail but i can't get it to work with hotmail or yahoo mail, could you please help me with this. any help would be greatly appreciated. THANKS IN ADVANCE
jaradgrant1 10 months ago
hi,
I tried doing the exact same thing.
But when i receive and email, instead of an image or document I receive a garbage value.
I am really new to PHP ..please help!!!!!!!!
maithilikoli 10 months ago
Thanks a lot for making and uploading this video. You helped me really a lot!
One question: how should I rewrite the codes if I want to have 2 or more files?
molnarcsilla 11 months ago
@molnarcsilla just separate each file by the attachment boundry. i wanna do a video on this soon, so if you can't figure it out persay - keep an eye out for that video.
optikalefxx 11 months ago
@optikalefxx can't wait :) thanks in advance
molnarcsilla 11 months ago
@optikalefxx I gave it up :) but no problem..
other question: how can I setup two e-mail addresses where the data to be sent?
is it possible to put the second email address to bcc? if yes, how? thanks in advance
molnarcsilla 11 months ago
Comment removed
molnarcsilla 11 months ago
Hey this script does not work on godaddy hosting. the mail function is not working in it. Can u check into this.
chaseranster85858 1 year ago
Hey this code does not work in a godaddy host. The mail function does not support godaddy . can u check into this
chaseranster85858 1 year ago
@chaseranster85858 don't use godaddy - get a better host provider. OR, call godaddy because I know it does work with them. You probably aren't paying them enough.
optikalefxx 1 year ago
Comment removed
mrtentje 1 year ago
Everything works fine, except for one thing. It doesn't show the message in het e-mail? Does anybody knowwhat the solution is?
I have the following: $header .= "--".$uid."\r\n"; $header .= "Content-type:text/plain; charset=UTF8\r\n"; $header .= "Content-Transfer-Encoding: 7bit\r\n\r\n"; $header .= $message."\r\n\r\n";
mrtentje 1 year ago
@mrtentje double and tripple check you have exactly the right thing, look at the other video i did on this as a troubleshooting and tips.
optikalefxx 1 year ago
Everything's working fine except gmail. E-mails sent this method aren't received by gmail.com . Any solutions will be appreciated :-)
redos111 1 year ago
hey so I'm sry to say but I'm another person with a problem! lol
but any ways I'm constantly getting the please enter the right file type message even when I attach the right file type! I have checked my code and all seams right?!?! any ideas? thank u in advanced
-Daniel
dansta93 1 year ago
Comment removed
sanstors 1 year ago
Hey, I know you must be really busy with all that you do. But I could really use your help with this form. I'm receiving the same error as "lingachannel" (2 months ago):
Warning: file_get_contents(...) [function.file-get-contents]: failed to open stream: No such file or directory in /home/...thank_you.php on line 205
The email sends and I receive an attachment, but it's always 0kb and can never be accessed. Would you be able to help me with this?
Thank you,
Danice
studdnature 1 year ago
@studdnature I was also receiving the attachments with 0kb and then I found out that I was missing the last line of the following block:
$header .= "--".$uid."\r\n";
$header .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
RavanaMad 8 months ago
Please, if anybody can help me.... my mail is rotcivchen@hotmail.com
thanks a lot
Unforgiv3nii 1 year ago
hi, thanks a lot for the code. It work great..!!! but i have just one problem. The attachment arrives to my mailbox like text. Just text... if a send a PDF file, i got a TEXT like this "JVBERi0xLjMNJf////8NMSAwIG9iag08PA0vVGl0bGUgKP7/AGQAbwBjAHUAbQBlAG4AdCkNL1Byb2R1Y2VyIChBbXl1bmkgUERGIENvbnZlcn".
Unforgiv3nii 1 year ago
Hi,
Great video. Having trouble with the code, the attachments are not being decode, and show as 0kb in the email. Sure it's something simple. Could I send you my code, or could you supply a working copy.
Thanks
Ed
erf05 1 year ago
@erf05 double and tripple check that all your case and spelling is right.
then, if it still doesn't work. PM me.
optikalefxx 1 year ago
Could someone provide me with this txt or the php file? my email is Maria2k6@gmail.com
Thanks,
Maria
moreno0scar 1 year ago
Hi,
I am getting a syntax error on this particular code:
$content = chunk_split(base64_encode(file_get_contents($file)));
I really dont know why....Could you please help me out.
Because the error which I get is Syntax Error: Unexpected T_Variable
pitambar 1 year ago
@pitambar
check this good code lines:
//we receive the temporal name of the file
$temp_name = $_FILES['attachment']['tmp_name'];
$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
Unforgiv3nii 1 year ago
Thanks for this very useful video tutorial! It's explained in a very simple way so all my compliments to that!
kristijanmne 1 year ago
Now, I had a little bit a problems with some parts of the code because I tried to accommodate some part of it to suite my needs and to see how it works.
I noticed 2 things:
- If I use (') - as a quotation marks inside of (") it will nor work. It only works with (\"). Usually in PHP when I work with HTML it does not matter.
- In some parts of the code it is OBLIGATORY to put double new lines/paragraphs like this: "\r\n\r\n". Otherwise it will not work again.
kristijanmne 1 year ago
@kristijanmne I though that it should be useful also to put this to on comments even if I only can guess why is it happening.
Another thing that I wanted to ask is this:
"Content-Transfer-Encoding: 7bit" - it is ok to put it for "Content-type: text/html" and is there any thing that I or others should know about this when I send mails in "charset=utf-8"?
Beside this, it works like a charm for me!
Greetings from Montenegro (EU)! :)
kristijanmne 1 year ago
Comment removed
pitambar 1 year ago
Thank you for this clear example.
I did exactly as you done, but am getting an empty file (0 kb size). I saw also your second video with the error example, i checked every letter in my file but find nothing.
Am getting this error:
Warning: file_get_contents() [function.file-get-contents]: Filename cannot be empty in /home/.................. /sendfile.php on line 30
success
Thank you
Yosef
lingachannel 1 year ago
@lingachannel Your filename is not. Send me a pm with your code
optikalefxx 1 year ago
@optikalefxx
Thank you for your quick replay
Look to the txt file please: (url)
tranem.linga.org/Temp/sendmail.txt
Thanks a lot
Yosef
lingachannel 1 year ago
@optikalefxx I found the problem
my mistake was here:
$temp_name = $_FILES['attachment']['temp_name'];
it should be:
$temp_name = $_FILES['attachment']['tmp_name'];
Thank you
lingachannel 1 year ago
Comment removed
lingachannel 1 year ago
Comment removed
qwertzpoi 1 year ago
Comment removed
qwertzpoi 1 year ago
How should I modify the code when I want to be able to send the email either with attachment or without. Because when I try without it obviously writes me No attachement.
qwertzpoi 1 year ago
@qwertzpoi SOLVED
qwertzpoi 1 year ago
@qwertzpoi you need to first get rid of the 'if else' check for the file being posted. The !emtpy($_FILES['attachment']['name'] bit
and then you need to kill the attachment "part" basically the code underneath of the comment // file attachment. Cuz with no attachment you don't want to send those headers.
optikalefxx 1 year ago
Really good video it was exactly what I was looking for but I got parse error on this line
$header .= "Content-Disposition: attachment; filename=\"",.$file_name."\"\r\n\r\n";
can you please look at it? thanks
qwertzpoi 1 year ago
@qwertzpoi You've got a random comma it looks like
optikalefxx 1 year ago
@optikalefxx Thanks I am stupid, I wondered what the parse error could be. I suspected the quotes. Anyway thanks for the awesome piece of code.
qwertzpoi 1 year ago
Comment removed
qwertzpoi 1 year ago
Thanks a lot! you are the man!
What if i needed to send more than two attachments? how would i change the code?
latlov 1 year ago
Thanks a lot! you are the man!
What if i needed to send more than two attachments? how would i change the code?
latlov 1 year ago
Thanks a lot! After wathcing your movie and lots of swearing, I finally made it and actually started to understand what I was doing.
Tip for attachments: I found out that my Ubuntu Server limited my file attachment size to 2 MB. You have to edit the php.ini file and edit the line "upload_max_filesize =2MB"
stonheneg79 1 year ago
@stonheneg79 good point, i hope everyone reads this and notes that they might need to make this change.
optikalefxx 1 year ago
am having trouble with this code.... the attachment is not showing what type of file it is...
007chiranth 1 year ago
@007chiranth Make sure you spelled your content types correctly
optikalefxx 1 year ago
Excellent video!!!
asy1mpo 1 year ago
Comment removed
asy1mpo 1 year ago
Comment removed
asy1mpo 1 year ago
How can I get copy of this code in text format
mrgarrett2000 1 year ago
@mrgarrett2000 as soon as square bracket.com is ready all the sources will be up
optikalefxx 1 year ago
@optikalefxx ETA? (from a weekly watcher)
ransombot 1 year ago
@ransombot ask my designer lol. After this tuesday serious development begins. Say 1 month before you see something up there.
optikalefxx 1 year ago
Comment removed
raphagcwill 1 year ago
Man, thats was amazing. I need some help to finally make my php work. Would you be willing to have a look at it and then we can talk about how much you would charge?
raphagcwill 1 year ago
@raphagcwill sure thing, send me a PM.
optikalefxx 1 year ago
I am getting a corrupt attachment. Any ideas?
snacktreat 1 year ago
@snacktreat Did you watch the trouble shooting video? If so you cam send me your code and I'll see what's up
optikalefxx 1 year ago
So to you guys that are having issues check the following:
- You are not using windows, seriously
- its $_POST not $POST
- text/plain not txt/plain
- Make sure you punctuation matches mine
- PHP variables start with a $
optikalefxx 1 year ago
What am I doing wrong? I cannot get this script to work for me. I have entered the necessary info into the spaces provided yet I cannot get the form to work. Any suggestions?
Sassci 1 year ago
@Sassci send me your code
optikalefxx 1 year ago
There is a easy way to get the extension:
$filename = "test.doc";
$ext = end(explode(".",$filename));
echo $ext; // doc
asorsuehtam 2 years ago
Brilliant!
optikalefxx 2 years ago
What I mean is, instead of just getting the last 4 you could do something like this:
$dot_index = stripos($base, ".");
$extension = substr($base, $dot_index);
That will return the extension and then you can just compare it to all the elements in the allowed extension array and not have to worry about hard-coding the extension length.
warlord90210 2 years ago
@warlord90210 i thought about that. But you would need to get the LAST index of "." because we can't gurantee there is only 1 dot. so i figured it was safer to get the end, because we can gurantee the end is the extension
optikalefxx 2 years ago
Very true very true, I thought about that myself after I posted the comment.
Oh well, either way is good I suppose, great tutorial as always.
warlord90210 2 years ago
Great video, could you instead check for the length of the array for the different types allowed and then you wouldn't have to keep a constant 4 for the length?
warlord90210 2 years ago