jjfletcher90 Posted July 9, 2011 Share Posted July 9, 2011 Hi I am frustrated and need a solution!!! I have an upload.php and want to send an email once the user selects the upload button <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; @mail($name@myemailaddress.com, $subject, $msg, $headers); header("Location:http://www.exactusign.com/members/Members_Area/uploaded.html"); } else { echo "Sorry, there was a problem uploading your file."; } } ?> I am receiving the following error when I try to run the code - can anyone help me understand this? ERROR: Parse error: syntax error, unexpected '@' in D:\Hosting\3945010\html\website\members\Members_Area\upload.php on line 34 Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/ Share on other sites More sharing options...
Cagecrawler Posted July 9, 2011 Share Posted July 9, 2011 Your string isn't in quotes: @mail($name.'@myemailaddress.com', $subject, $msg, $headers); Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240647 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 received the following error: Warning: move_uploaded_file(/upload/123.jpg) [function.move-uploaded-file]: failed to open stream: No such file or directory in D:\Hosting\3945010\html\website\members\Members_Area\upload.php on line 30 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'D:\Temp\php\phpF03.tmp' to '/upload/123.jpg' in D:\Hosting\3945010\html\website\members\Members_Area\upload.php on line 30 Sorry, there was a problem uploading your file Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240650 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Ok.... code is now functioning - yet I am not receiving the email acknowledgement when the file uploaded Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240652 Share on other sites More sharing options...
Cagecrawler Posted July 9, 2011 Share Posted July 9, 2011 Are the mail settings in your php.ini set correctly? Try removing the @ at the beginning of the mail function, it's blocking any possible error messages that may help diagnose what's wrong. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240663 Share on other sites More sharing options...
gizmola Posted July 9, 2011 Share Posted July 9, 2011 First of all remove the @ symbol from in front of the mail() command while you're debugging this. You may not be getting email from the server because it is being spam filtered, or there could be a configuration issue. The MX for your domain is: ;; ANSWER SECTION: exactusign.com. 3600 IN MX 0 smtp.secureserver.net. exactusign.com. 3600 IN MX 10 mailstore1.secureserver.net. So your authoritative mail servers appear to be controlled/hosted by your hosting company, and mail should be sent to them for forwarding and retrieval, otherwise it will be considered to be spam by almost all other email servers these days, and often blocked outright. Whatever email system you are using currently probably has a whitelist, so you should put in a whitelist entry for the email first and see if it appears. You should contact your hosting company and find out what the required configuration is for you to be able to send mail from your server. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240665 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Thanks CageCrawler... I think I am just doing this wrong... when I uploaded the file to the server - all functioned correctly except I did not get an email right away - sometime later I did receive an email and it was from: noreply@onlineserver.cc and there was no subject, no message... Am I supposed to do more with the coding below to make this work? Thanks Again This is the complete code: <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; @mail($name.'info@website.com', $subject, $msg, $headers); header("Location:http://www.website.com/members/Members_Area/uploaded.html"); } else { echo "Sorry, there was a problem uploading your file."; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240666 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Thanks Gizmola... I do not have issues with the mail server... my Outlook seems to be functioning well unless I misunderstand what you mean? This seems to be a simple issue with the code I am trying to work with - I must not have it coded right! :'( Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240669 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Gizmola, how does one go about creating this whitelist entry? Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240670 Share on other sites More sharing options...
PFMaBiSmAd Posted July 9, 2011 Share Posted July 9, 2011 Your code is not setting the $name, $subject, $msg, and $headers variables, so of course it will be a little difficult for the email to get sent. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240672 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 is there a resource available or sample I may review that will demonstrate how to Re: setting the $name, $subject, $msg, and $headers variables, so the email can be sent. Thanks in Advance ! You guys are Awsome! Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240673 Share on other sites More sharing options...
gizmola Posted July 9, 2011 Share Posted July 9, 2011 Thanks Gizmola... I do not have issues with the mail server... my Outlook seems to be functioning well unless I misunderstand what you mean? This seems to be a simple issue with the code I am trying to work with - I must not have it coded right! :'( There are probably multiple issues with your code. Try reading mail and see if that helps. Plenty of examples there. For whitelisting in your email client: http://www.nerd4rent.com/reports/whitelists.htm Often ISP's also have a whitelist feature that works directly with their email server. When you get mail in your outlook it was first sent to your ISP's email server, and outlook is simply pulling the email from there. So if your ISP has already rejected the email as spam, a whitelist entry in outlook won't help you, but you need to cover all your bases. The things I brought up have to do with how servers work with the email system these days. The php mail() command by default can make a connection and send an email off. However, the server receiving the mail will be doing some verification, and if the server is not listed as the official "MX" or mail exchanger for the domain, or if it doesn't have an SPF listing or doesn't have a reverse dns entry, then most likely the email will be classified as spam. Often servers will look at a combination of these things and simply reject the email, so it never even gets into the server or is immediately deleted before you would ever have a chance to receive it. The first thing you need to do however, is address the issues with your code. A blank email is either going to be rejected or deleted, and there doesn't seem to be the proper variables set in your script for mail() to even create a valid email. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240678 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Gizmola, I have made modifications to the code: Would you review and give me your opinion? I will also read the suggested URL you have provided concerning email systems.... <?php $target = "upload/"; $target = $target . basename( $_FILES['uploaded']['name']) ; $ok=1; //This is our size condition if ($uploaded_size > 350000) { echo "Your file is too large.<br>"; $ok=0; } //This is our limit file type condition if ($uploaded_type =="text/php") { echo "No PHP files<br>"; $ok=0; } //Here we check that $ok was not set to 0 by an error if ($ok==0) { Echo "Sorry your file was not uploaded"; } //If everything is ok we try to upload it else { if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; @mail($name.'webmaster@website.net', $subject, $message, $headers); $to = "webmaster@website.net"; $subject = "File Upload"; $message = "A File has been uploaded to the Server."; $from = "webmaster@website.com"; $headers = "From:" . $from; header("Location:http://www.websitecom/members/Members_Area/uploaded.html"); } else { echo "Sorry, there was a problem uploading your file."; } } ?> Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240681 Share on other sites More sharing options...
gizmola Posted July 9, 2011 Share Posted July 9, 2011 You are setting your variable after you've already made the mail() call. I don't see where $name is being set or coming from. Try $to = "webmaster@website.net"; $subject = "File Upload"; $message = "A File has been uploaded to the Server."; $from = "webmaster@website.com"; $headers = "From:" . $from; mail($to, $subject, $message, $headers); header("Location:http://www.websitecom/members/Members_Area/uploaded.html"); Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240685 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 does the mail have to have a @ in front ie: @mail Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240687 Share on other sites More sharing options...
gizmola Posted July 9, 2011 Share Posted July 9, 2011 No, and we specifically said to remove it previously. The @ in front of a php function causes it to suppress any error messages it might otherwise generate. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240688 Share on other sites More sharing options...
jjfletcher90 Posted July 9, 2011 Author Share Posted July 9, 2011 Oh yes .... very well ... It looks as though the code is working yet the lag time for the email server to deliver the email is absolutely terrible - almost 40 minutes before it arrives - something wrong with the Godaddy email servers I think! We are on a shared server, maybe this is what the problem is! Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240689 Share on other sites More sharing options...
gizmola Posted July 10, 2011 Share Posted July 10, 2011 Open a ticket with godaddy on it, but check the email headers on your received email first so you have more information on what is going on. It includes timestamps. Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240690 Share on other sites More sharing options...
jjfletcher90 Posted July 10, 2011 Author Share Posted July 10, 2011 Thanks Gizmola - Your Awsome - Great Help! This subject is completed! Quote Link to comment https://forums.phpfreaks.com/topic/241529-php-email-coding-assistance-please/#findComment-1240695 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.