Hello, I have set up a form where people can visit my site and type the "to, from, subject, and message" in a form to send an email. I have also setup a form where they can attach a file to their email. The current php that process this is: <? $headers = "MIME-Version: 1.0\r\n"; $headers.= "Content-type: text/html; charset=iso-8859-1\r\n"; $headers.= "From: $from\r\n"; if (mail($to, $subject, $message, $headers)) echo "Message Sent!"; else echo "Failed to send message."; ?> Code (markup): This works perfectly. But my question is, what do I need to add to this script to make it send the attached file as well? Thanks!
I am new to scripting and I am having trouble getting this working. Is there a simple script that I can just add to my script above? Because these new script is WAY different than what my form is created to do. Thanks.
sorry, maybe you need to learn how to program better, or at least look on a site dedicated to programming, rather than giving me a negative reputation point simply because you don't understand
Here is the function I used First have the form to upload file, (I will leave this for now) function attach($AttmFile,$FileName) { global $ms,$head; $Text=$ms; $Html=$ms; if ($Text=="") {$Text=" ";$Html=" ";} $OB="----=_OuterBoundary_000"; $IB="----=_InnerBoundery_001"; $Html=$Html?$Html:preg_replace("/\n/","{br}",$Text) or die("neither text nor html part present."); $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail."; $headers ="MIME-Version: 1.0\r\n"; $headers.=$head; $headers.="X-Priority: 0\n"; $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n"; $Msg ="This is a multi-part message in MIME format.\n"; $Msg.="\n--".$OB."\n"; $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n"; $Msg.="\n--".$IB."\n"; $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n"; $Msg.="Content-Transfer-Encoding: quoted-printable\n\n"; $Msg.=$Text."\n"; $Msg.="\n--".$IB."--\n"; $patharray = explode ("/", $AttmFile); $Msg.= "\n--".$OB."\n"; $Msg.="Content-Type: application/zip;\n\tname=\"".$FileName."\"\n"; $Msg.="Content-Transfer-Encoding: base64\n"; $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"; $fd=fopen ($AttmFile, "r"); $FileContent=fread($fd,filesize($AttmFile)); fclose ($fd); $FileContent=chunk_split(base64_encode($FileContent)); $Msg.=$FileContent; $Msg.="\n\n"; $Msg.="\n--".$OB."--\n"; $ms=$Msg; $head=$headers; } PHP:
Here's my PHP Script that is supposed to Upload the file, attach it, and then send an email: <? $target_path = "uploads/"; $target_path = $target_path . basename( $_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded"; } else{ echo "There was an error uploading the file, please try again!"; } function attach($name) { global $ms,$head; $Text=$ms; $Html=$ms; if ($Text=="") {$Text=" ";$Html=" ";} $OB="----=_OuterBoundary_000"; $IB="----=_InnerBoundery_001"; $Html=$Html?$Html:preg_replace("/\n/","{br}",$Text) or die("neither text nor html part present."); $Text=$Text?$Text:"Sorry, but you need an html mailer to read this mail."; $headers ="MIME-Version: 1.0\r\n"; $headers.=$head; $headers.="X-Priority: 0\n"; $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n"; $headers.= "From: $from\r\n"; $headers.= "Reply-To: $replyto\r\n"; $Msg ="This is a multi-part message in MIME format.\n"; $Msg.="\n--".$OB."\n"; $Msg.="Content-Type: multipart/alternative;\n\tboundary=\"".$IB."\"\n\n"; $Msg.="\n--".$IB."\n"; $Msg.="Content-Type: text/plain;\n\tcharset=\"iso-8859-1\"\n"; $Msg.="Content-Transfer-Encoding: quoted-printable\n\n"; $Msg.=$Text."\n"; $Msg.="\n--".$IB."--\n"; $patharray = explode ("/", $AttmFile); $Msg.= "\n--".$OB."\n"; $Msg.="Content-Type: application/zip;\n\tname=\"".$FileName."\"\n"; $Msg.="Content-Transfer-Encoding: base64\n"; $Msg.="Content-Disposition: attachment;\n\tfilename=\"".$FileName."\"\n\n"; $fd=fopen ($name, "r"); $FileContent=fread($fd,filesize($name)); fclose ($fd); $FileContent=chunk_split(base64_encode($FileContent)); $Msg.=$FileContent; $Msg.="\n\n"; $Msg.="\n--".$OB."--\n"; $ms=$Msg; $head=$headers; } $headers ="MIME-Version: 1.0\r\n"; $headers.="Content-Type: multipart/mixed;\n\tboundary=\"".$OB."\"\n"; $headers.= "From: $from\r\n"; $headers.= "Reply-To: $replyto\r\n"; if (mail($to, $subject, $message, $headers)) echo "<h1>Message Sent!</h1>"; else echo "<h1>Failed to send message.</h1>"; ?> PHP: The problem is, it uploads the file fine, the email is sent fine, but the file is NOT being attached to the email. How do I configure it to attach the file?