2

I am absolutely bad at PHP programming. I have no experience with it, but I wanted a form on my website with a mail script. So like almost every other person with no experience on a language, I googled up one and customized it.

mail_send.php

<?php 
if(isset($_POST['submit'])){
$to = "my@mailadress.com"; // I just did this for privacy     
$from = $_POST['email'];     
$name = $_POST['name'];    
$subject = "Form submission";    
$message = $name . " " . $from . " wrote the following:" . "\n\n" . 
$_POST['message'];    

$headers = "From:" . $from;    
mail($to,$subject,$message,$headers);
echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
}
?>

and here the HTML code: index.html

 <form role="form" id="feedbackForm" class="text-center" action="mail_send.php" method="post">
          <div class="form-group">
            <label for="name">Naam</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
            <span class="help-block" style="display: none;">Voer uw naam in..</span></div>
          <div class="form-group">
            <label for="email">E-Mail</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
            <span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
          <div class="form-group">
            <label for="message">Bericht</label>
            <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
            <span class="help-block" style="display: none;">Voer een bericht in.</span></div>
          <button type="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
        </form>

So I have uploaded both files to my Website Server so I've tested it online, but still without success. Any smart guys being able to help me?

Thanks in advance :)

Jort D.
  • 25
  • 1
  • 2

4 Answers4

2

Please modify button tag

<button type="submit"  name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
sabeerzabi
  • 450
  • 4
  • 13
1
  1. I suggest to do not use mail function directly. Better use something like https://github.com/PHPMailer/PHPMailer and use it through SMTP of a real e-mail account of yours.
  2. You are checking in your IF clause $_POST['submit'] - But I don't see where did you set this name="submit" in your html code... you need to add name="submit" to your button
  • 1
    In addition to other right answers, I would suggest you to consider Ivan’s answer. Most of the hosting companies are not allowing to use mail function because of the security issues. So using PHPMailer is the best option to use SMTP. – rawsly Jan 06 '18 at 10:55
0

Use name = submit in button tag.

<button type="submit"  name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>

After that also check your spam folder. Sometime you don't get messages in inbox.

Rupal
  • 1,111
  • 6
  • 16
0

Modify as per your requirement and I hope this code will send you message to inbox directly rather than span

<?php 
    if(isset($_POST['submit'])){
        $to = "Email Address Here"; // I just did this for privacy     
        $from = $_POST['email'];     
        $name = $_POST['name'];    
        $subject = "Form submission";    
        $message = $name." ".$from." wrote the following:". "\n\n". $_POST['message'];    

        $headers = "MIME-Version: 1.0" . "\r\n";
        $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n";   
        $headers .= 'From: <info@example.com>' . "\r\n";

        mail($to,$subject,$message,$headers);
        echo "Mail Sent. Thank you " . $name . ", we will contact you shortly.";
    }
?>
<!DOCTYPE html>
<html>
<head>
    <title>Mail Example</title>
    <link rel="stylesheet" type="text/css" href="style.css">
</head>
<body>

     <form role="form" id="feedbackForm" class="text-center" action="" method="post">
          <div class="form-group">
            <label for="name">Naam</label>
            <input type="text" class="form-control" id="name" name="name" placeholder="Name">
            <span class="help-block" style="display: none;">Voer uw naam in..</span></div>
          <div class="form-group">
            <label for="email">E-Mail</label>
            <input type="email" class="form-control" id="email" name="email" placeholder="Email Address">
            <span class="help-block" style="display: none;">Voer een geldig e-mailadres in.</span></div>
          <div class="form-group">
            <label for="message">Bericht</label>
            <textarea rows="10" cols="100" class="form-control" id="message" name="message" placeholder="Message"></textarea>
            <span class="help-block" style="display: none;">Voer een bericht in.</span></div>
          <button type="submit" name="submit" id="feedbackSubmit" class="btn btn-primary btn-lg" style=" margin-top: 10px;"> Verstuur</button>
        </form>
</body>
</html>
Ravi Shrimali
  • 111
  • 1
  • 9