PHP表单不起作用。电子邮件未发送

时间:2016-11-22 11:00:34

标签: php html forms email

我的网站上有联系表格,似乎没有发送电子邮件。当我测试它时,它在服务器上。

这是表格。

    <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>

这是PHP代码。

   <?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);

        }
        }
     ?>

我已经将我的电子邮件地址更改为虚拟电子邮件地址,但是当我提交此表单时,我确实没有收到任何电子邮件。

提前致谢! :)

2 个答案:

答案 0 :(得分: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);
?>

答案 1 :(得分:0)

php mail-function需要一组不同的参数:

Php Mail function

在将消息传递给php的邮件()

之前,您必须在邮件中嵌入$ name和$ email。