-1

I have a contact form on my website and it does not seem to be sending emails. It was on a server when I have been testing it.

Here is the form.

    <form  action="" method="post" name="form">
        <input type="text" name="name" />
        <input  type="email" name="email" />
        <textarea name="message" ></textarea>
        <input  name="submit" type="submit" value="Submit">
    </form>

And here is the PHP code.

   <?php
        if(isset($_POST["submit"])){
        if($_POST["name"]==""||$_POST["email"]==""||$_POST["message"]==""){
        echo "Please fill in the contact form";
        }else{

        $to = "example@gmail.com";
        $subject = "Contact Form";
        $name= $_POST['name'];
        $email= $_POST['email'];
        $message= $_POST['message'];
        $headers = "From: example@gmail.com";

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

        }
        }
     ?>

I have changed my email address to a dummy one there but it does I have not recieved any emails when I do submit this form though.

Thanks in advance! :)

Allan
  • 351
  • 1
  • 2
  • 11

2 Answers2

2
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";

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

//syntax mail(to,subject,message,headers,parameters);
?>
0

The php mail-function requires a different set of parameters:

Php Mail function

You have to embed $name and $email into your message before passing it to php's mail()

Craden
  • 145
  • 6