forsakenmemory Posted October 17, 2007 Share Posted October 17, 2007 I have the following bits of code and wondering if any one can help my figure out how to get the attched file to arrive with the email i get the following error message Upload: IS155-036.jpg Type: image/pjpeg Size: 18.1171875 Kb Temp file: /tmp/phpDDKjCz Stored in: upload/IS155-036.jpgThe was an error! Please go back and try again. any help i would be most thankful for! cheers HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <html> <head> <title> Contact</title> <link rel="STYLESHEET" href="main.css" type="text/css"> </head> <body> <br/><br/> <table align=center border="0" cellspacing="0" cellpadding="0" width="790" bgcolor="ffffff" bordercolorlight="#666666" bordercolordark="#808080"> <tr> <td width=220 valign=center> <blockquote> <form method="post" action="contact_action2.php" enctype="multipart/form-data">> Fields marked (*) are required<br/><br/> Email:* <br/> <input type="text" name="EmailFrom"><br/> Full Name:* <br/> <input type="text" name="Name"><br/> Tel:<br/> <input type="text" name="Tel"><br/> Website:<br/> <input type="text" name="Website"><br/> Subject: <br/> <input type="text" name="Subject"><br/> </blockquote> </td> </tr> <tr> <td valign=top colspan=3> <blockquote> Enquiry:*<br/> <textarea name="Enquiry" cols="60" rows="8"></textarea><br/><br/> <label for="file">Filename:</label> <input type="file" name="file" id="file" /><br/><br/> <input type="submit" value="Submit"><br/> </form> </blockquote> </td> </tr> </table> </body> </html> PHP: <?php $EmailFrom = Trim(stripslashes($_REQUEST['EmailFrom'])); $EmailTo = "admin@webdesigndigital.com"; $Subject = Trim(stripslashes($_REQUEST['Subject'])); $Name = Trim(stripslashes($_REQUEST['Name'])); $Tel = Trim(stripslashes($_REQUEST['Tel'])); $Website = Trim(stripslashes($_REQUEST['Website'])); $Enquiry = Trim(stripslashes($_REQUEST['Enquiry'])); $File = $_FILES; function checkEmail($EmailFrom) { if(eregi("^[a-zA-Z0-9_]+@[a-zA-Z0-9\-]+\.[a-zA-Z0-9\-\.]+$]", $EmailFrom)) { return FALSE; } list($Username, $Domain) = split("@",$EmailFrom); if(getmxrr($Domain, $MXHost)) { return TRUE; } else { if(fsockopen($Domain, 25, $errno, $errstr, 30)) { return TRUE; } else { return FALSE; } } } if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } if (Trim($EmailFrom)=="") { print "You did not enter an email address! Please try again"; exit; } if(checkEmail($EmailFrom) == FALSE) { print "The email address you entered was not valid. please try again"; exit; } if (Trim($Name)=="") { print "You did not enter a Name. Please try again."; exit; } if (Trim($Enquiry)=="") { print "You did not enter an enquiry. Please go back and try again."; exit; } $Body = ""; $Body .= "Name: " . $Name . "\n" . "\n"; $Body .= "Tel: " . $Tel . "\n" . "\n"; $Body .= "Website: " . $Website . "\n" . "\n"; $Body .= "Enquiry: " . $Enquiry . "\n"; $success = mail($EmailTo, $Subject, $Body, $File, "From: <$EmailFrom>"); if ($success){ print "<meta http-equiv=\"refresh\" content=\"0;URL=ok.htm\">"; } else{ print "The was an error! Please go back and try again."; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/73648-attaching-files-to-emails/ Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 your mail() call is invalid. it should be: mail ( string to, string subject, string message [, string additional_headers [, string additional_parameters]] ) it looks like you have $File as the additional_headers, but that's not the way to attach a file, assuming that's your intent. you'll need to look into MIME headers and how to use them to attach an image to an email. better yet, look for an existing PHP class that already does this. Quote Link to comment https://forums.phpfreaks.com/topic/73648-attaching-files-to-emails/#findComment-371548 Share on other sites More sharing options...
forsakenmemory Posted October 17, 2007 Author Share Posted October 17, 2007 ok thanks, i'm not sure as to why my mail call is invalid as it works fine if i remove the attachment part of the script. unless you just mean outdated. i will look into MIME headers etc. thanks Quote Link to comment https://forums.phpfreaks.com/topic/73648-attaching-files-to-emails/#findComment-371558 Share on other sites More sharing options...
BlueSkyIS Posted October 17, 2007 Share Posted October 17, 2007 your mail call is invalid because you're putting $File where additional headers are supposed to be. email probably just ignores it or worse actually sends the file as additional headers. additional headers are like what you incorrectly put in the additional_parameters location. some examples: "From: <$EmailFrom>" "To: <$toEmail>" "Return-path: <$EmailFrom>" when you figure out MIME headers, they and the binary image data will (typically) be included in the body, not the headers. on the other hand: additional_parameters (optional) The additional_parameters parameter can be used to pass an additional parameter to the program configured to use when sending mail using the sendmail_path configuration setting. For example, this can be used to set the envelope sender address when using sendmail with the -f sendmail option. Quote Link to comment https://forums.phpfreaks.com/topic/73648-attaching-files-to-emails/#findComment-371559 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.