Hi

I am preapring a website form where the resume needed to be uploaded and it should send an email to me along with upload as attachment. Please let me know the error in this below forms:

== HTML Form:

<form method="post" name="mailform" action="emailnew.php">
<table width="200"  border="0" cellspacing="0">
  <tr>
    <td width="62">Name:</td>
    <td width="134">
      <input name="name" type="text" id="name">
   </td>
  </tr>
  <tr>
    <td>Email:</td>
    <td><input name="email" type="text" id="email"></td>
  </tr>
  <tr>
    <td valign="top">Message:</td>
    <td><textarea name="body" cols="45" rows="10"></textarea></td>
  </tr>
<tr>
    <td valign="top">Select Resume:</td>
    <td><input type="hidden" name="MAX_FILE_SIZE" value="1000" />
     Upload File: <input name="uploadedfile" type="file" /> <br /></td>
  </tr>
</table>
  <br>
  <input type="submit" name="Submit" value="Submit">
  <input type="reset" name="Reset" value="Reset">
</form>

== PHP Code:

<?php
$target_path = "./resupload/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['body'];
if ($name != "" AND $email != "" AND $body != "") {
$sendto = "test@test.com";
$from ="Web Resume";
$subject = "Resume Uploaded in Website";
$message = "This is a message from your site
From: $name
Email: $email
Message: $body";
mail("$sendto", "$subject", "$message");
echo "Your message was sent";
if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
    echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
}
?>

Please let me know the changes to be done for my php file to make sure that upload file send attachment and deletes from server (web-hosting directory also)

Member Avatar for diafol
<form method="post" name="mailform" action="emailnew.php">

Won't work because you need an 'enctype' attribute.

Can you please re-script the form and php file for me if possible

Member Avatar for diafol

> Can you please re-script the form and php file for me if possible

You're joking right?

I've told you you need an enctype attribute in your form tag. It's up to you what you do with that info. You can Google it, search w3schools or the php.net manual for upload files.

Hi,

I have added the below script in my html form:

enctype="multipart/form-data">

After adding the command line, I am getting the below error messgae:

There was an error uploading the file, please try again!

The information is sending to my email address but the attachment does not get uploaded and sends to my email address too.

Member Avatar for diafol

You don't have the right code for attaching a file in an email. Also, do your upload checks BEFORE creating an e-mail and sending.

I assume you're using Tizag's code:

$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!";
}

Your error may come from here: $target_path = "./resupload/";
php usually deals with webroot references, so it may be beneficial to just use the relative reference from the page:

$target_path = "resupload/";

Also make sure that this directory is writable.

I am getting the below error message

There was an error uploading the file, please try again!Your message was sent

The email send to my personal email address but without attachment. Can you send the script to my email address - nrkumarvj@gmail.com - if possible

You have two main problems here:

1. Uploading doesn't seem to be working, so there's no file for to attach to the e-mail. You can't merely declare a variable called $target_path and have the file go anywhere- you need to copy it from PHP's temp directory to your upload directory first.

To fix this, you need to *move* the file to the directory you specified...

<?php

$target_path = "./resupload/";
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'],$target_path);
$name = $_POST['name'];
$email = $_POST['email'];
$body = $_POST['body'];
if ($name != "" AND $email != "" AND $body != "") {
    $sendto = "test@test.com";
    $from = "Web Resume";
    $subject = "Resume Uploaded in Website";
    $message = "This is a message from your site
From: $name
Email: $email
Message: $body";
    mail("$sendto", "$subject", "$message");
    echo "Your message was sent";
    if (is_uploaded_file($_FILES['uploadedfile']['tmp_name'])) {
        echo "The file " . basename($_FILES['uploadedfile']['name']) . " has been uploaded";
    } else {
        echo "There was an error uploading the file, please try again!";
    }
}
?>

You need something like Line 5 to do that.


2. The part of your PHP that sends the e-mail isn't set up to attach a file, so even if you fix Problem #1, you need to do something that makes an e-mail with an attachment.

Member Avatar for diafol

To send an attachment you need to send additional headers.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.