w3hello.com logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML videos Categories
Sending email forms in HTML without seeing outlook

Here i have pasted a complete code for sending mail without opening any outlook or using gmail credentials etc. It uses PHP for sending mail. hope this helps you.

if(isset($_POST['submit'])) {

if(trim($_POST['contactname']) == '') {
    $hasError = true;
} else {
    $name = trim($_POST['contactname']);
}

if(trim($_POST['subject']) == '') {
    $hasError = true;
} else {
    $subject = trim($_POST['subject']);
}

if(trim($_POST['ContactNum']) == '' &&
is_numeric($_POST['ContactNum'])) {
    $hasError = true;
} else {
    $Contacting = trim($_POST['ContactNum']);
}

//Check to make sure sure that a valid email address is submitted 
if(trim($_POST['email']) == '' &&
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/",$_POST['email']))
 {
    $hasError = true;
}  else {
    $email = trim($_POST['email']);
}
if(trim($_POST['message']) == '') {
    $hasError = true;
} else {
    if(function_exists('stripslashes')) {
        $comments = stripslashes(trim($_POST['message']));
    } else {
        $comments = trim($_POST['message']);
    }
}

//----------------------Email Validation-----------------//
    function EmVal($e)
    {
        return
preg_match("/^([a-zA-Z0-9])+([a-zA-Z0-9._-])*@([a-zA-Z0-9_-])+([a-zA-Z0-9._-]+)+$/",$e);
    }


//If there is no error, send the email
if(!isset($hasError)) {
        $emailTo = 'abc@abc.com';
        $body = "Name: $name 

Email: $email 

Subject: $subject 

Comments:
 $comments 

Contact Number:
 $Contacting";
        $headers = 'From: WebBestow <'.$emailTo.'>' . "
" . 'Reply-To: ' . $email;

        mail($emailTo, $subject, $body, $headers);
        $emailSent = true;}


}
 ?>

You can udpate fields as per your requirments. And set action="youpage.php". this code should be in html document of yourpage.php





© Copyright 2018 w3hello.com Publishing Limited. All rights reserved.