php - Sending image attachment -
i have php form, i'm trying send image attachment. fixed few things in code.
- i'm not sure if send image (because had problems it)
- the problem nothing shown in page (when script below ran) when open on server
index.php
not button
here code:
<?php include_once("functions.php"); // process $action = isset($_post["action"]) ? $_post["action"] : ""; if (empty($action)) { // send contact form html $output = "<form action='#' style='display:none'> <input type='file' id='image' name='image' maxlength=50>"; } require("class.phpmailer.php"); $email_to = "someone@gmail.com"; // 1 recieves email $email_from = "someone@someone.net"; $dir = "uploads/$filename"; chmod("uploads",0777); function uploadimage($image) { if ((($_files["image"]["type"] == "image/gif") || ($_files["image"]["type"] == "image/jpeg") || ($_files["image"]["type"] == "image/pjpeg") || ($_files["image"]["type"] == "image/jpg") || ($_files["image"]["type"] == "image/png")) && ($_files["image"]["size"] < 2097152) && (strlen($_files["image"]["name"]) < 51)) { if ($_files["image"]["error"] > 0) { echo "return code: " . $_files["image"]["error"]; } else { echo "upload: " . $_files["image"]["name"] . "<br />"; echo "type: " . $_files["image"]["type"] . "<br />"; echo "size: " . ($_files["image"]["size"] / 1024) . " kb<br />"; echo "temp file: " . $_files["image"]["tmp_name"] . "<br />"; if (file_exists("images/" . $_files["image"]["name"])) { echo $_files["image"]["name"] . " exists. "; } else { move_uploaded_file($_files["image"]["tmp_name"], "images/" . $_files["image"]["name"]); } } } else { echo "invalid file"; } $filename = $_files["image"]["type"]; $dir = "uploads/$filename"; chmod("uploads",0777); $success = copy($_files[images][tmp_name], $dir); if ($success) { echo " files uploaded successfully<br>"; sendit(); } }//end of upload func' function sendit() { // global $attachments,$email_to,$email_msg,$email_subject,$email_from; $mail = new phpmailer(); $mail->issmtp();// send via smtp $mail->host = "localhost"; // smtp servers $mail->smtpauth = false; // turn on/off smtp authentication $mail->from = $email_from; $mail->addaddress($email_to); $mail->addreplyto($email_from); $mail->wordwrap = 50;// set word wrap //now attach files submitted $mail->addattachment("uploads"."/".$_files["image"]["type"]); $mail->ishtml(false);// send html } ?>
thank in advance!
for problem 1:
try send mail class without variables put it. make procedural code sending mail own address , see if arrives.
for problem 2:
you putting text $output
never outputting $output
.
Comments
Post a Comment