简体   繁体   English

Html php电子邮件表单不起作用

[英]Html php email form not working

Hello I am trying to add a html email form to my website but cannot get it to work. 您好我正在尝试将html电子邮件表单添加到我的网站,但无法使其工作。 The following is the code I currently have but when I try the form I don't receive an email. 以下是我目前的代码,但是当我尝试表单时,我没有收到电子邮件。

<?php 
$action=$_REQUEST['action']; 
if ($action=="")    /* display the contact form */ 
    { 
    ?> 
    <form  action="" method="POST" enctype="multipart/form-data"> 
    <input type="hidden" name="action" value="submit"> 
    Your name:<br> 
    <input name="name" type="text" value="" size="30"/><br> 
    Your email:<br> 
    <input name="email" type="text" value="" size="30"/><br> 
    Your message:<br> 
    <textarea name="message" rows="7" cols="30"></textarea><br> 
    <input type="submit" value="Send email"/> 
    </form> 
    <?php 
    }  
else                /* send the submitted data */ 
{ 
$name=$_REQUEST['name']; 
$email=$_REQUEST['email']; 
$message=$_REQUEST['message']; 
if (($name=="")||($email=="")||($message=="")) 
    { 
    echo "All fields are required, please fill <a href=\"\">the form</a> again."; 
    } 
else{         
        $from="From: $name<$email>\r\nReturn-path: $email"; 
        $subject="Message sent using your contact form"; 
        mail("****************", $subject, $message, $from); 
        echo "Email sent!"; 
        } 
    }   
?> 

I recommend using PHPMailer . 我建议使用PHPMailer

It will save you a lot of trouble and there are plenty of guides, with freely available default configs where all you need to do is modify the contents, sender and recipient of the email. 它将为您节省很多麻烦,并且有大量指南,免费提供默认配置,您只需要修改电子邮件的内容,发件人和收件人即可。

first - use $_POST, not $_REQUEST; 首先 - 使用$ _POST,而不是$ _REQUEST; second - is there right settings on your server? 第二 - 你的服务器上有正确的设置吗? maybe there is no mail support; 也许没有邮件支持; and the last - 4th argument of mail function is not "from", it's headers where you can also set mime-type and others.. 邮件功能的最后一个 - 第四个参数不是“from”,它的标题你也可以设置mime-type和其他..

$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

the error is in this line : 错误在这一行:

mail("****************", $subject, $message, $from);

replace the asterisks with your email 用您的电子邮件替换星号

mail function returns boolean, check whether it is sending or not sending. mail函数返回boolean,检查是否正在发送。 Change your mail code like below and try to know whats happening. 更改您的邮件代码,如下所示,并尝试知道发生了什么。

` `

if (mail("himmerz@gmail.com", $subject, $message, $from)) {
echo 'send';
} else {
echo 'not send';
}

` `

mail("****************", $subject, $message, $from); 

改成:

mail($email, $subject, $message, $from); 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM