Jump to content

PHP EMAIL CODING ASSISTANCE PLEASE!


jjfletcher90

Recommended Posts

Hi  :confused:

 

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

Link to comment
Share on other sites

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

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.";
  }
  }

?>

Link to comment
Share on other sites

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!

 

:'(

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.";
  }
  }

?>

Link to comment
Share on other sites

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");

 

Link to comment
Share on other sites

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!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.