Jump to content

Sassci

New Members
  • Posts

    1
  • Joined

  • Last visited

    Never

Profile Information

  • Gender
    Not Telling

Sassci's Achievements

Newbie

Newbie (1/5)

0

Reputation

  1. Sassci

    Help

    I am completely new to PHP and I need some help trying to figure this out. I am trying to put together a script that will allow e-mails with attachments. I used a video tutorial and did all that was stated to do yet I am not having any luck. I have the Apache server thing installed and working on my computer so I can check this thing out...to no avail. If anyone can guide me in this I would greatly appreciate it. What I have done so far is listed below. Thankz... <?php if(isset($_POST) && !empty($_POST)) { if(!empty($_FILES['attachment']['name'])) { $file_name = $_FILES['attachment']['name']; $temp_name = $_FILES['attachment']['tmp_name']; $file_type = $_FILES['attachment']['type']; $base = basename($file_name); $extension = substr($base, strlen($base)-4, strlen($base)); $allowed_extensions = array(".doc","docx",".pdf",".png",".jpg"); if(in_array($extension,$allowed_extensions)) { $from = $_POST['email']; $to = "enteryouremail@address.com"; // I have my contact email here $subject = "Test with attachment"; $message = "This is a test"; $file = $temp_name; $content = chunk_split(base64_encode(file_get_contents($file))); $uid = md5(uniqid(time())); $header = "From: ".$from."\r\n"; $header .= "Reply-To: ".$replyto."\r\n"; $header .= "MIME-Version 1.0\r\n"; $header .= "Content-Type: multipart/mixed; boundary=\"".uid."\"\r\n\r\n"; $header .= "This is multi-part message in MIME format. \r\n"; $header .= "--".uid."\r\n"; $header .= "Content-type:txt/plain; charset=iso-8859-1\r\n"; $header .= "Content-Transfer_Encoding: 7bit\r\n\r\n"; $header .= $message. "\r\n\r\n"; $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"; $header .= $content."\r\n\r\n"; if (mail($to, $subject, "", $header)) { echo "Success"; } else { echo "Failed"; } exit(); } else { echo "File type not allowed"; } } ?> <html> <body> <p>Contact Form</p> <form action="index.php" method="post" enctype="multipart/form-data" name="form1"> <p>First Name: <input type="text" name="firstname"></p> <p>Last Name: <input type="text" name="lastname"></p> <p>E-mail: <input type="text" name="email"></p> <p>Phone Number: <input type="text" name="phonenum"></p> <p>URL: <input type="text" name="url"></p> <p>Project Summary: <input type="textarea" name="prosum" id="prosum"></p> <p>Upload File: <input type="file" name="filename"></p> <p><input type="submit" name="Submit" value="Submit"></p> <?php } ?> </form> </body> </html>
×
×
  • 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.