0

I have tried to resolve the issue myself (and some websites and questions here in Stockoverflow), but without success.

My problem is I'm trying to make my form actually send an email to the specified address down there, but it is absolutely not working. Any idea where my code is bugging?

here is a piece of it, can you see any mistake?

Thanks!

<?php 
if(isset($_POST['submit'])){
$to = "email@gmail.com"; // this is my Email address
$from = $_POST['email']; // this is the sender's Email address
$first_name = $_POST['name'];
$subject = "Form submission";
$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);
mail($from,$subject2,$message2,$headers2); // sends a copy of the message to the sender
}
?>

<body id="getademo">
<div class="titlepage">
        <h1 id="introdemo">GET IN TOUCH</h1>
        <p id="mikshahf">We will get back to you soon!</p>
        </div>
    <div id="form1">
        <div id="formform">
            <form>
                    <p>
                        <input name="name" type="text" class="feedback-input" placeholder="Name" id="name" />
                    </p>
                    <p>
                        <input name="email" type="text" class="feedback-input" id="email" placeholder="Email" />
                    </p>
                    <p>
                        <textarea name="message" class="feedback-input" id="comment" placeholder="Message"></textarea>
                    </p>
                    <div class="submit">
                        <input name="submit" type="submit" value="SEND" id="button-blue"/>
                    </div>
                </form>
            </div>
        </div>


</body>
Tripduc
  • 31
  • 1
  • 11
  • Do both emails fail, or just one of them? – Barmar Aug 10 '16 at 21:13
  • Have you ever been able to send mail from PHP on this server? – Barmar Aug 10 '16 at 21:16
  • Have you checked the server's sendmail log? – Barmar Aug 10 '16 at 21:17
  • `
    ` defaults to a GET method when POST isn't specifically implied. That's one (major) reason here. Once you've given it a post method, try it again. If it fails, check your spam.
    – Funk Forty Niner Aug 10 '16 at 23:09
  • @Barmar Yeah I was able to send email using forms with various templates I tried. But then when I tried to apply this php function to my existing html form it didn't worked. – Tripduc Aug 11 '16 at 00:35
  • @Fred -ii- Eureka! adding a method="post" made it work just fine! Thanks! – Tripduc Aug 11 '16 at 00:38
  • I love that word *"Eureka"* ;-) Glad to hear it all worked out, *cheers* – Funk Forty Niner Aug 11 '16 at 00:39
  • @Tripduc I reopened the question since (that possible duplicate that it was marked as) stating to use error reporting would not have signaled an error. It actually fails silently. I posted an answer below if you wish to mark it as accepted. – Funk Forty Niner Aug 11 '16 at 00:51

1 Answers1

2

As I stated in comments; <form> alone defaults to a GET method when POST isn't specifically implied.

Therefore, you need to add it.

<form method="post">

Error reporting would not have signaled an error. It actually failed on you silently.

Funk Forty Niner
  • 74,450
  • 15
  • 68
  • 141