Skip to content Skip to sidebar Skip to footer

Php Form Upload And Email

I have the following code, ideally, it is expected that the user shall upload a file(image/video) when submitting the form, but it is not compulsory though.

Solution 1:

it runs on page load

enclose mail send feature in

if(isset($_POST['Submit']) && ($_POST['Submit']) == 'Send' )
{
  /* process only when submit button whose name='Submit' 
     and value= 'Send' is pressed
     entire PHP code */
}

if file has not been uploaded, it throws a warning.

check before attaching it in PHP

if((empty($_POST['attachment'])) || (empty($_FILES['attachment']))){
    //file is not attached, show error
}else{
 //file is attached, process it and send via mail
}

Post a Comment for "Php Form Upload And Email"