how to connect contact form to email in php

Solutions on MaxInterview for how to connect contact form to email in php by the best coders in the world

showing results for - "how to connect contact form to email in php"
Noah
14 Apr 2020
1<?php
2if (isset($_POST['Email'])) {
3
4    // EDIT THE 2 LINES BELOW AS REQUIRED
5    $email_to = "you@yourdomain.com";
6    $email_subject = "New form submissions";
7
8    function problem($error)
9    {
10        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
11        echo "These errors appear below.<br><br>";
12        echo $error . "<br><br>";
13        echo "Please go back and fix these errors.<br><br>";
14        die();
15    }
16
17    // validation expected data exists
18    if (
19        !isset($_POST['Name']) ||
20        !isset($_POST['Email']) ||
21        !isset($_POST['Message'])
22    ) {
23        problem('We are sorry, but there appears to be a problem with the form you submitted.');
24    }
25
26    $name = $_POST['Name']; // required
27    $email = $_POST['Email']; // required
28    $message = $_POST['Message']; // required
29
30    $error_message = "";
31    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
32
33    if (!preg_match($email_exp, $email)) {
34        $error_message .= 'The Email address you entered does not appear to be valid.<br>';
35    }
36
37    $string_exp = "/^[A-Za-z .'-]+$/";
38
39    if (!preg_match($string_exp, $name)) {
40        $error_message .= 'The Name you entered does not appear to be valid.<br>';
41    }
42
43    if (strlen($message) < 2) {
44        $error_message .= 'The Message you entered do not appear to be valid.<br>';
45    }
46
47    if (strlen($error_message) > 0) {
48        problem($error_message);
49    }
50
51    $email_message = "Form details below.\n\n";
52
53    function clean_string($string)
54    {
55        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
56        return str_replace($bad, "", $string);
57    }
58
59    $email_message .= "Name: " . clean_string($name) . "\n";
60    $email_message .= "Email: " . clean_string($email) . "\n";
61    $email_message .= "Message: " . clean_string($message) . "\n";
62
63    // create email headers
64    $headers = 'From: ' . $email . "\r\n" .
65        'Reply-To: ' . $email . "\r\n" .
66        'X-Mailer: PHP/' . phpversion();
67    @mail($email_to, $email_subject, $email_message, $headers);
68?>
69
70    <!-- include your success message below -->
71
72    Thank you for contacting us. We will be in touch with you very soon.
73
74<?php
75}
76?>
Elisa
28 Jan 2020
1if (empty($emailError) && empty($messageError)) {
2	// all the code should go here
3}
4
Nele
13 Jun 2019
1<?php
2if ($_SERVER['REQUEST_METHOD'] === 'POST') {
3	// your other code here
4}
5
Alice
24 May 2020
1<!DOCTYPE html>
2<head>
3    <meta charset="utf-8">
4    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
5    <title>contact form</title>
6</head>
7
8<body>
9
10<link href="contact-form.css" rel="stylesheet">
11
12<div class="fcf-body">
13
14    <div id="fcf-form">
15    <h3 class="fcf-h3">Contact us</h3>
16
17    <form id="fcf-form-id" class="fcf-form-class" method="post" action="contact-form-process.php">
18        
19        <div class="fcf-form-group">
20            <label for="Name" class="fcf-label">Your name</label>
21            <div class="fcf-input-group">
22                <input type="text" id="Name" name="Name" class="fcf-form-control" required>
23            </div>
24        </div>
25
26        <div class="fcf-form-group">
27            <label for="Email" class="fcf-label">Your email address</label>
28            <div class="fcf-input-group">
29                <input type="email" id="Email" name="Email" class="fcf-form-control" required>
30            </div>
31        </div>
32
33        <div class="fcf-form-group">
34            <label for="Message" class="fcf-label">Your message</label>
35            <div class="fcf-input-group">
36                <textarea id="Message" name="Message" class="fcf-form-control" rows="6" maxlength="3000" required></textarea>
37            </div>
38        </div>
39
40        <div class="fcf-form-group">
41            <button type="submit" id="fcf-button" class="fcf-btn fcf-btn-primary fcf-btn-lg fcf-btn-block">Send Message</button>
42        </div>
43
44        <div class="fcf-credit" id="fcf-credit">
45            <a href="https://www.freecontactform.com/form-guides/html-email-form" target="_blank">HTML Email Form</a> from FreeContactForm.com
46        </div>
47
48    </form>
49    </div>
50
51</div>
52
53</body>
54</html>
queries leading to this page
contact form php emailphp contact form direct to emailhow does php contact form sends mailphp mail function from the contact form submissionhow to connect contact form to email in phphow to send an email using phpsend contact form to mail in html format using php mail functioncreate contact form using php email functionphp contact simple emailsend contact form using php mailer classcontact us to email phpworking email contact form phpcontact form mail connection in phphow to get email from contact form in html and php codemail php with contact form simpl econtact from email sendg php contact form php send to emailsend contact form data to email using phpphp contact form using smtphow do i send an email from a contact form with php 3fcontact us page in php send emailphp mail function for contact formsetup email for contact us in html using phpphp for contact form to send emailworking contact us php send emailsend mail php contact formhow to write contact us form to send mail for a particular mail id using php contact us php send emailhow to send email from contact form phpphp contact us form send emailemail contact form phphow to use phpmailer on a contact formcontact form php send emailphp code to send email from contact formphpmailer contact form examplephp contact form with phpmailer examplehow to receive email in php contact formhow to write contact us form to send mail using php script for contact form with php mailerphp code for contact form to send emailphp contact form script to send emailcontact form send email phpphp send mail contact formhow to send an email with phphtml contact form with php mailphp contact form 22email sent 22 responsehtml contact form send email phpcustom php contact form send emailsend email contact form phphow to send mail using php with contact formcontact form with flaskhow to email form in phpusing php send email from contact formhow to send contact form on email in php on submit buttonworking contact form without phpcontact form with phpmail for your websitehow to send contact mail usnig phpsend email to from contact form phphtml contact form emailcontact form in php with mail functionsend contact form mail phpcontact us form with phpmailercontact form php send email githuybsend mail from localhost in php using contact formhow to create contact form in html php mysql 26 emailphp send contact form to emailcontact form php with phpmailer smtphow to make php contact us to send emailphp send emails contact formhow to setup php email form as contact formsend mail script for contact form phpcontact form mail send phpphp mail function on contact us fromcontact us form send email in phpsimple mail connection for contact form in phphow to make contact form and send email in phpcontact form submit to email phpcontact email phpcontact us form in php with mailphp mail script for contact formphp script send contact form emailphp send contact form to email via smtpphp contact page mailtohow to send email in php using contact formphp sample contact mailing codephp mail contact formhow make contact form php not use mail serverhow make contact form php now use mail serversend contact us page directly through email with php in html format send mail 2c contact form 2c server 2c phpcontact form that sends and email out that works phphow to give the mail connection to the contact form in phpbest php email contact formhow to get contact form 7 data in in php code before emailphp contact form send to emaila php contact form to send emailphp send email contact form mail connection for contact form in phpsetup contact form mail phpphp contact form with php mailer examplehtml contact form send email with phpcontact form that sends and email out phpcontact form send mail phpcontact form with smtp phpcontact us send email phpsimple html contact form to send email in phpcontact form with email sending in phpemail php contact formhow to make contact forms in php using mailphpmailer example contact formsend email from contact form phpcontact form in php with mail function in localhost awa melvinephp contact form send emailcontact us form with email phphow to send contact form to an email in phphow to contact phpmailer in html formphp email contact formjs contact form emailsend contact us email phpphp contact us form issue in sending mailsend email php contact formcontact form to send email phpcontact form php send email addresshow to make contact us form in php with mailhow to send contact form 7 mail by php scriptsend contact form data to email in phpcontact form send email using php mailphp mailer script for contact formphp code for sending contact mailhow to create a contact form using phpmailercontact form mail in phpsimple php contact form to send emailphp contact form conect with mail serverhow to add phpmailer in php contact formphp send mail from contact formhow does php contact form mailsend contact form data to email smtp using phpcontact form email phpsend contact us page directly through email with phphow to connect contact form to email in php