php - PHPMailer email being sent without an attachment -
i trying use phpmailer email form results, , getting email. reason though email coming through without attachments. must doing wrong, don't know what. appreciated.
here php:
<?php require_once('class.phpmailer.php'); if (isset($_post["submit"])) { $name = $_post['name']; $location = $_post['location']; $desc = $_post['desc']; if(isset($_post['submit'])) { $msg = ''; if (array_key_exists('userfile', $_files)) { // first handle upload // don't trust provided filename - same goes mime types // see http://php.net/manual/en/features.file-upload.php#114004 more thorough upload validation $uploadfile = tempnam(sys_get_temp_dir(), sha1($_files['userfile']['name'])); if (move_uploaded_file($_files['userfile']['tmp_name'], $uploadfile)) { // upload handled // create message // should somewhere in include_path require 'phpmailerautoload.php'; $mail = new phpmailer(); $mail->from = 'gallery@####.co.uk'; $mail->fromname = 'gallery robot'; $mail->addaddress('gallery@####.co.uk'); $mail->subject = 'phpmailer file sender'; $mail->body = "my message body"; // attach uploaded file $mail->addattachment($uploadfile, 'my uploaded file'); if ($mail->send()) { $msg = "message sent!"; } else { $msg = "mailer error: " . $mail->errorinfo; } } else { $msg = 'failed move file ' . $uploadfile; } } }
and here html form:
<form role="form" method="post" action="index.php" enctype="multipart/form-data"> <div class="form-group"> <label for="name">your name</label> <input class="form-control" placeholder="john smith" type="text" name="name" required value="<?php echo htmlspecialchars($_post['name']); ?>"> </div> <div class="form-group"> <label for="location">location</label> <input class="form-control" placeholder="south-west bank of trout pool." type="text" name="location" value="<?php echo htmlspecialchars($_post['location']); ?>"> </div> <div class="form-group"> <label for="desc">picture description</label> <textarea class="form-control" name="desc" rows="3" placeholder="a picture of 6lbs trout, biggest season."><?php echo htmlspecialchars($_post['desc']); ?></textarea> </div> <div class="form-group"> <label for="btn-upload">upload image file</label> <input type="file" id="uploaded_file" name="uploaded_file" value="<?php echo htmlspecialchars($_post['file']); ?>"> </div> <div class="progress"> <div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="45" aria-valuemin="0" aria-valuemax="100" style="width: 76%" data-toggle="tooltip" title="this useless , broken. sorry that."> <span class="sr-only">45% complete</span> </div> </div> <input id="submit" name="submit" type="submit" value="upload" class="btn btn-primary"> </form>
if important know, form inside modal.
**edit: ** have updated code using example on phpmailer github , i'm receiving no message @ all. have done wrong now?
Comments
Post a Comment