Recieve form message to my email

Website URL : http://clonesites.kesug.com/school/index.html

scroll down to form or conact us form .

Error Message

I want to be able to recieve messages that users send to my gmail account that I put in the php code , I don’t want to send them , I don’t want to STMP or PHP mailer , unfortunately I dodn’t find a solution yet.

Other Information

I’m using the free hosting, here is the code :

<?php
// Check if the form is submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    // Get form data
    $name = $_POST["name"];
    $email = $_POST["email"];
    $phone = $_POST["phone"];
    $message = $_POST["message"];

    // Recipient email address (your Gmail address)
    $to = "I used my gmail [email protected]";

    // Email subject
    $subject = "Contact Form Submission";

    // Email message
    $email_message = "Name: $name\nEmail: $email\nPhone: $phone\nMessage:\n$message";

    // Additional headers
    $headers = "From: $email";
    // Send the email
    if (mail($to, $subject, $email_message, $headers)) {
        echo "Message sent successfully!";
        // Redirect the user to a thank you page or back to the contact form
         header("Location: thank_you.html");
         exit();
    } else {
        echo "Message could not be sent.";
    }
}
?>

PHP mail() is not supported on free hosting:

8 Likes

There is an example here which shows you how to use SMTP mail to send email from a form. I set it up on my site and it works properly.

(Don’t forget to install dependencies with composer first)

5 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.