Question

I created a simple contact form as follows.

    <form method="post" action="mail_receive.php">

<label>Name&nbsp;&nbsp;*</label>
<input name="name" placeholder="Type Here">

<label>Email&nbsp;&nbsp;*</label>
<input name="email" type="email" placeholder="Type Here">

<label>Phone No&nbsp;&nbsp;*</label>
<input name="phone" placeholder="Type Here">

<input id="submit" name="submit" type="submit" value="">

And php file called mail_receive.php

<?php
$name = $_POST['name'];
$email = $_POST['email'];
$phone = $_POST['phone'];
$from = 'From: Someone'; 
$to = 'admin@gmail.com';
$subject = 'Ticket Ordering';
$body = "From: $name\n E-Mail: $email\n Phone:\n $phone";

if (isset($_POST['submit'])) {
    if ($name != '' && $email != '' && $phone != '') {
        if (mail ($to, $subject, $body, $from)) { 
            echo '<p>Your message has been sent!</p>';
        } else { 
            echo '<p>Something went wrong, go back and try again!</p>'; 
        }
     } else {
        echo '<p>Please fill all required fields !!</p>'; 
     }
}?>

}

And i uploaded to my hosting. Although I can fill up the form and submit, I can't receive email to my inbox. Is there any wrong?

Was it helpful?

Solution

With mail, it's meant to be

mail($to, $subject, $message, $headers);

Try something like this:

$to = "youremailaddress@whatever.com";

$subject = "Your tickets yo";

$headers = "From: someone@someone.com\r\n";
$headers .= "Reply-To: someone@someone.com\r\n";
$headers .= "MIME=VERSION:1.0\r\n";
$headers .= "Content-Type: text/plain; charset=UTF-8\r\n;"

$message = "Nice tickets bro.";

mail($to, $subject, $message, $headers);

And please I hope it's just for example purposes, but please don't actually be sending it to admin@gmail.com because obviously (unless you ARE actually admin@gmail.com, you wont recieve the e-mail.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top