$n = $_FILES['image']['name']; move_uploaded_file($t, $upload . $n); //upload file to directory //save form data in Database Comments_form::save_data($user_name, $user_comment, $email, $comment_date, $phone); //start send email $to = $email; $subject = 'Hello,your comments'; $message = 'Comment date ' . $comment_date . "\r\n"; $message .= 'Phone ' . $phone . "\r\n"; $message .= 'Comment ' . $user_comment . "\r\n"; $headers = "Content-type: text/html; charset=windows-1251 \r\n"; $headers .= "From: Birthday Reminder bogdandvinin@example.com \r\n"; mail($to, $subject, $message, $headers); //send email //end send email } else { exit; //if file size > 0.5m exit } } else { //if user don't upload file - we save other data to Database //save form data to Database $query = Comments_form::save_data($user_name, $user_comment, $email, $comment_date, $phone); if ($query == TRUE) { // if needed, we can provide information to the user (but in our case JavaScript reports) } else { $_SESSION['info'] = 'Error to add comment'; } } }