php contact form

#Contact form

NOTE:  NEEDS An SMTP service on the website server.

<?php
    //Message Vars
    $msg = '';
    $msgClass = '';
    //check for the submit
    if(filter_has_var(INPUT_POST,'submit')){
    //Get form Data
    $name = htmlspecialchars($_POST['name']);
    $email = htmlspecialchars($_POST['email']);
    $message = htmlspecialchars($_POST['message']);

    //Check Required Fields
    if(!empty($email) && !empty($name) && !empty($message)){
        //passed
        //check enail
        if(filter_var($email, FILTER_VALIDATE_EMAIL) === false){
            //Failed
            $msg = 'email format is incorrect';
            $msgClass='alert-danger';
        }else{
            //Passed
            //send to Recipient email needs an email host to send it
            $toEmail = '[email protected]';

        }
        
    }else{
        //failed
        $msg = 'Please Fill in all fields completely';
        $msgClass='alert-danger';
        //Email Subject
        $subject = 'contact request from '.$name;
        //creat body of the email
        $body = "<h2>Contact Request</h2>
        <h4>Name</h4><p>'.$name.'</p>
        <h4>Email</h4><p>'.$email.'</p>
        <h4>Message</h4><p>'.$message.'</p>";

        //Email Header
        $headers = "MIME-VERSION: 1.0" . "\r\n";
        $headers .= "Content-Type:text/html;charset=UTF-8" . "/r/n";

        //Additional Headers
        $headers.= "From: ".$name."<" .$email. ">". "\r\n";

        if(mail($toEmail, $subject, $body, $headers)){
            //Email sent
            $msg = 'Email sent';
            $msgClass = 'alert-success';

        }else{
            $msg = 'Email has not been sent';
            $msgClass = 'alert-danger';
    }
    }
?>

0
7

                                    &lt;?php
&nbsp;&nbsp;
if($_POST) {
&nbsp;&nbsp;&nbsp;&nbsp;$visitor_name = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$visitor_email = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$email_title = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$concerned_department = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$visitor_message = &quot;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;$email_body = &quot;&lt;div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(isset($_POST['visitor_name'])) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$visitor_name = filter_var($_POST['visitor_name'], FILTER_SANITIZE_STRING);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;&lt;b&gt;Visitor Name:&lt;/b&gt;&lt;/label&gt;&nbsp;&lt;span&gt;&quot;.$visitor_name.&quot;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(isset($_POST['visitor_email'])) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$visitor_email = str_replace(array(&quot;\r&quot;, &quot;\n&quot;, &quot;%0a&quot;, &quot;%0d&quot;), '', $_POST['visitor_email']);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$visitor_email = filter_var($visitor_email, FILTER_VALIDATE_EMAIL);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;&lt;b&gt;Visitor Email:&lt;/b&gt;&lt;/label&gt;&nbsp;&lt;span&gt;&quot;.$visitor_email.&quot;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(isset($_POST['email_title'])) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_title = filter_var($_POST['email_title'], FILTER_SANITIZE_STRING);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;&lt;b&gt;Reason For Contacting Us:&lt;/b&gt;&lt;/label&gt;&nbsp;&lt;span&gt;&quot;.$email_title.&quot;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(isset($_POST['concerned_department'])) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$concerned_department = filter_var($_POST['concerned_department'], FILTER_SANITIZE_STRING);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;&lt;b&gt;Concerned Department:&lt;/b&gt;&lt;/label&gt;&nbsp;&lt;span&gt;&quot;.$concerned_department.&quot;&lt;/span&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(isset($_POST['visitor_message'])) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$visitor_message = htmlspecialchars($_POST['visitor_message']);
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;label&gt;&lt;b&gt;Visitor Message:&lt;/b&gt;&lt;/label&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div&gt;&quot;.$visitor_message.&quot;&lt;/div&gt;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if($concerned_department == &quot;billing&quot;) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$recipient = &quot;[email protected]&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if($concerned_department == &quot;marketing&quot;) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$recipient = &quot;[email protected]&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else if($concerned_department == &quot;technical support&quot;) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$recipient = &quot;[email protected]&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$recipient = &quot;[email protected]&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;$email_body .= &quot;&lt;/div&gt;&quot;;
&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;$headers&nbsp; = 'MIME-Version: 1.0' . &quot;\r\n&quot;
&nbsp;&nbsp;&nbsp;&nbsp;.'Content-type: text/html; charset=utf-8' . &quot;\r\n&quot;
&nbsp;&nbsp;&nbsp;&nbsp;.'From: ' . $visitor_email . &quot;\r\n&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;if(mail($recipient, $email_title, $email_body, $headers)) {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo &quot;&lt;p&gt;Thank you for contacting us, $visitor_name. You will get a reply within 24 hours.&lt;/p&gt;&quot;;
&nbsp;&nbsp;&nbsp;&nbsp;} else {
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;echo '&lt;p&gt;We are sorry but the email did not go through.&lt;/p&gt;';
&nbsp;&nbsp;&nbsp;&nbsp;}
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
} else {
&nbsp;&nbsp;&nbsp;&nbsp;echo '&lt;p&gt;Something went wrong&lt;/p&gt;';
}
?&gt;

0
0
Are there any code examples left?
Create a Free Account
Unlock the power of data and AI by diving into Python, ChatGPT, SQL, Power BI, and beyond.
Sign up
Develop soft skills on BrainApps
Complete the IQ Test
Relative searches
contact us form in php and mysql how to make a working contact form php a simple contact form in php script with html a simple contact form in php script a simple contact form in php my contact form displays my php script how to create a contact form using php php contact form scritp create contact form php how to setup contact form through php how to make a contact form with html, css and php contact us form with php contact form 7 in php code html contact form in php html php user contact form how to develop a Working Contact Form with php contact me php contact php code php tutorial contact form source code php tutorial contact form how to create a contact us page in php simple contact form with php php contact forms with sql custom html and php contact form contact us form submit in php website contact form without php how to create a contact frome using php php contact form in html page php contact form send php contact form with database connection contact form pphp php form example contact how to make a contact form in php simple php contact form example how to make contact form work in php contact form using html php working contact us using php how do i make a php contact form work How to Create a Working Contact Form in PHP basic contact us php script contact in php contact form 7 for php how to create contact form in html php mysql contact form.php how to setup contact form in php php script for contact form php contactos Contact page HTML PHP is it necessary to add php in contact form create working contact form using html css php contact form in php with database setup form php -contact create a content form php -contact create a setup form php -contact codes to create php contact form creating a working contact form php php code for contact form code php contact form create a php contact form php contact form option values how to create contact us form in php with database contact pages php creating a PHP contact form php contact form sample with source code php contact form sample Easy PHP Contact Form Script a sample php save contact form a simple php save contact form how to create contact form with php php make contact form work php contact us form with source code php contact form library add php code in contact form 7 php send contact form contact us form in php with php and mysql create simple contact form php add php code for contact-form-7 contact form with php code how to create a contact me php page contact form html and php html contact us form with php database code in php contact form inPHP php contact us form with database source code html contact.php contact php script Create Working Contact Form Using js, PHP | Contact Form Design contact form submitting php contact form using php only how to use html php contact form on your website how to use php contact form on server contact form jusing php contact.php code how to do a contact us function in php contact form php worf simple contact form php code simple contact form in php contact form 7 additional php add php in contact form 7 html inner php contact forms how to add php code in contact form 7 contact us php script a simple contact form with php easy php contact form script gratis contact us form using php php for contact form how to make working contact form in php contact us page php contact form ph how make contact form php contact us form php mysql contact us page in html phpp working contact form html php hw to creat contact form php html contact form without php contact form without php php contact send how to make a contact form without php how to create a contact form using php and html code for an html and phph contact form include contact form 7 on php =complete contact form in html php simple contact us form html and php\ contact us form html and php external contact form php handler php contact formular post contact.php submit contact form php how to make html contact us form wok with php how to make contact us form in php php form contact contact us php example contact us form example html action php code contact form php mysql php contact us JavaScript contact form without PHP forms/contact.php contact us form php code PHP contact form with css contact form para php how to get contact form 7 data in in php code php contact us page working contact form without php contact form php send sending your contact us form php how to make contact form in html with php create contact form with php php working contact box formulaire contact php php contact form submit button simple contact form php custom contact form html php contact form php wp how to create a contact form in html php php script for contact us form create contact form html php php contact form function contact form php and html making a working contact from in php php contact form doe php simple contact from contact form php post contact form 7 php send contact form using php creation of contact form using php contact form html without php create a php contact form for html create a php contact form code for a contact form php php working contact form contact form made with PHP php contact form with results page php contact form with results do you need php for a working contact form contact us form php how to make a working contact us form without php code for contact form in php working contact us php contact form7 php code form contact php contactos form php php contact form script with validation html contact form 7 php code php contact us form with database how to make contact forms in php using mail how to make contact forms in php enquiry form php code design a contact us form with all fields as required html code save informoration in mobile contact in php simple working contact form php contact us form submission email code in php add php contact form working php contact form make a contact form with PHP mail complete working contact page how to create php contact form how to create a contact form for my website php php contact form w3schools how to create a workking contact form using php PHP contact form using SMTP create a working contact form php contact form code php javascript or php for contact form contact us html and php contact form submit php contact us page form php make contactform php php contact us send mail php and html contact send the contact us data message form php get in touh templates php how to contact form html site php file php contct us page with database download php contact us form with souced code contact us page in php soced code with datasnse create a contact form with html and php contact me form server how to make a contact form functional php enquiry form contact form with php and html php contact form and upload host standard contact form php contact us form functionality Write a PHP script to accept the feedback on workshop event from HTML form with details of username, email, phone number, date of event rating, session and store it an associative array. Display the consolidated report in table. contact form phph contactUsForm:function(){} php complete a form from other website js php html contact form contact form tutorial build a contact form with php php contact form advanced contact form php template create a contat form with php contact form with php web.dev how to make a working contact form with server code of php to get daata from the contact form in website enquiry form in php contact form tutorial php php contact us form tutorial free contact form with php,database, and javascript for website free php,database, and javascript contact form for website free php and javascript contact form for website conact form php contact form html php template simple contact us php form contact us page php code contact us page without db contact form php book how to test my php contact form making a contact form work php loacalhost/Faaize_corporate/contact.php creating a contact us page php create functional contact form php create funtional contact form php make a working form with php making a php contact form for HTML webpage php projects contact form php form for contact page contact form php source code action page php for contact simple html php contact form how to make a php contact form php conact forms streetphoto.infol/mailform.php reactionform.php add contact form in php file php code to submit contact form to email tutorial with example contact form html php tutorial best way to view php contact form messages sent from clients in a website best way to view php contact form messages sent from clients setup a contact us with php how to create a simple php contact form for portfolio how to create a simple php contact form php contact user to user php contact from user to user php contact form user to user php contact form to user to user index php script for index html form how to make a contact form in html and php email form tutorial contact formular php code how to make contact form php css contact form with php php contactformular contact us page using php contact us php php form message modern data entry forms in php mysql css contact us page in php with validation reading filelds contact form in php reading contact from in php file php contact page mail using query contact contact form using php contact html to php file generate page for form information in php contact us html php create a html php contact form html php contact form contact.php contactus php how to create php quote form how to crea e a php quote form Contact Form Using HTML, CSS, PHP contact form using php php contact form with validation free download php contact form source code &lt;form action=&quot;contact.php&quot; name=&quot;&quot; method=&quot;POST&quot;&gt; contact us with php function form backend php php contact detais to a server localhost:/phaliainternational/contact-us.php how to make contact process php how to get a contact form to work php php simple contact form php contact form script with validation type of contact form in php full contact form php working contact form php full working contact form php code how to create contact us page and email php contact us for using php full contact page php working contact form php code contactform/contactform.php contactform.php make a contact us using php fully working php contact form for website how to make a contact form with php contact us form in php contact php php free contact form php contact form example 2020 php contact form email sender example 2020 basic contact form php basic php contact form contact us in php adding working php form to website php mail contact form code making a contact form using php contact us page isuing php how to store contact form php details in database contact form html php contact form in php html contact form with php format contact form php html Contact form PHP script php contact form code simple php contact form what does php do for a contact form how to configure contact us in php working php contact form. php code for contact form contact us page in php php concact php contact form with validation php contact form\ simple contact form php download php creating contact form what is a php file in a contact form html php contact form example How do I create a contact us form in HTML and PHP? contact form for website using php modern contact form php html html and php contact form how to make a working php contact form php email contact form how to code contact us form in php real life contact form php php contact form script php contact form code download contact form php working PHP contact page php contact form example php contact form post Get In Touch php contact us PHP post contact form with php contact form source code create a working php form use php to add contact form in html php contact form tutorial contact us php code php contact us form HTML and PHP enquiry form php contact form for website contact form php code js contact form email login form php include contact form php file php html contact form php contact format contact form code in php contact page php contact form php php contact form
Made with love
This website uses cookies to make IQCode work for you. By using this site, you agree to our cookie policy

Welcome Back!

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign in
Recover lost password
Or log in with

Create a Free Account

Sign up to unlock all of IQCode features:
  • Test your skills and track progress
  • Engage in comprehensive interactive courses
  • Commit to daily skill-enhancing challenges
  • Solve practical, real-world issues
  • Share your insights and learnings
Create an account
Sign up
Or sign up with
By signing up, you agree to the Terms and Conditions and Privacy Policy. You also agree to receive product-related marketing emails from IQCode, which you can unsubscribe from at any time.
Creating a new code example
Code snippet title
Source