help required

the mail() function

Moderators: macek, egami, gesf

srinivas
New php-forum User
New php-forum User
Posts: 5
Joined: Fri May 13, 2011 4:06 am

help required

Postby srinivas » Wed May 02, 2012 3:08 am

new to php mail function. i have a requirement from a client that he wants attachments to the mail using a form in php. can anyone help me with sample code for the same. also do suggest me if any changes to php.ini page required.

User avatar
egami
php-forum GURU
php-forum GURU
Posts: 2196
Joined: Wed Oct 06, 2010 11:19 am
Location: Happy Valley, UT

Re: help required

Postby egami » Wed May 02, 2012 4:42 am


hamwisk
New php-forum User
New php-forum User
Posts: 11
Joined: Fri Mar 02, 2012 4:59 am

Re: help required

Postby hamwisk » Wed May 23, 2012 8:07 pm

Hi, while i'm waiting for help with my problem...

this is an example of a form:

Code: Select all

   <form enctype='multipart/form-data' action='upload.php' method='post'>
   <input type='hidden' name='MAX_FILE_SIZE' value='2000000' />
   <input name='uploaded_file' type='file' size='9' />
   <input type='submit' value='Upload' />
   </form>");

The file is uploaded to a temporary location on your server. I would move the file into another folder because i want to send multiple attachments and i want to check a few things like:

Code: Select all

$filename = basename($_FILES['uploaded_file']['name']);
//Сheck that we have a file
if((!empty($_FILES["uploaded_file"])) && ($_FILES['uploaded_file']['error'] == 0)) {
  //Check if the file's size is 2000Kb or less
  if ($_FILES["uploaded_file"]["size"] <= 2000000) {
    //Determine the path to which we want to save this file
      $newname = dirname(__FILE__).'/upload/'.$filename;
      //Check if the file with the same name is already exists on the server
      if (!file_exists($newname)) {
        //Attempt to move the uploaded file to it's new place
        if ((move_uploaded_file($_FILES['uploaded_file']['tmp_name'],$newname))) {
           echo "succes";         // you can add "include ("sendme.php");" here
        } else {
           echo "error";
        }
      } else {
           echo "file already exists";
      }
  } else {
           echo "file too big";
  }
} else {
           echo "no file";
}

after it's uploaded you can go on to send it.

You might check your php.ini for the maximum upload file size.


Return to “PHP coding => Mail”

Who is online

Users browsing this forum: No registered users and 1 guest