Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29917

php form doesn't send email [duplicate]

$
0
0

This question already has an answer here:

I have referred to many posts for this but with no luck. I am very new to php and tried the following to send a simple email from the site but it won't work. Please help what am I doing wrong. I hosted the website on a hosting domain

<form id="main-contact-form" name="contact-form" method="post" action="contact-us.send.php">
                                <div class="form-group">
                                    <input type="text" name="name" id="name" class="form-control" placeholder="Name" required>
                                </div>
                                <div class="form-group">
                                    <input type="email" name="email" id="email" class="form-control" placeholder="Email" required>
                                </div>
                                <div class="form-group">
                                    <input type="text" name="subject" id="subject" class="form-control" placeholder="Subject" required>
                                </div>
                                <div class="form-group">
                                    <textarea name="message" id="message" class="form-control" rows="8" placeholder="Message" required></textarea>
                                </div>
                                <button type="submit" name="submit" class="btn btn-primary">Send Message</button>
                            </form>

This is the php script contact-us.send.php which I took out of send email in php

<?php 
if(isset($_POST['submit'])){
    $to = "nikhilans45@gmail.com"; // this is your Email address
    $from = $_POST['email']; // this is the sender's Email address
    $first_name = $_POST['name'];

    $subject = $_POST['subject'];;
    $subject2 = "Copy of your form submission";
    $message = $first_name . ""  . " wrote the following:" . "\n\n" . $_POST['message'];
    $message2 = "Here is a copy of your message " . $first_name . "\n\n" . $_POST['message'];

    $headers = "From:" . $from;
    $headers2 = "From:" . $to;
    mail($to,$subject,$message,$headers);

    echo "Mail Sent. Thank you " . $first_name . ", we will contact you shortly.";
    // You can also use header('Location: thank_you.php'); to redirect to another page.
    }
?>

Viewing all articles
Browse latest Browse all 29917

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>