发送按钮网站

时间:2015-07-03 08:52:57

标签: php html forms sendmail send

我已经在我的网站上用PHP和HTML制作了一个联系表格。但它不起作用。如果我按下send按钮,我应该发送一封电子邮件,其中包含姓名,电子邮件,标题,消息,日期和时间。但它没有给我发电子邮件。请帮帮我......

HTML:

<form method="post" action="">
<ul>
    <li>
        <label>name*</label>
        <input type="text" class="wmfg_text" name="name" id="text_id" value="" />
    </li>
    <li>
        <label>email*</label>
        <input type="text" class="wmfg_text" name="eamil" id="text_id" value="" />
    </li>
    <li>
        <label>title*</label>
        <input type="text" class="wmfg_text" name="title" id="text_id" value="" />
    </li>
    <li>
        <label>message*</label>
        <textarea class="wmfg_textarea" name="message" id="textarea_id"></textarea>
    </li>
    <li>
        <input type="submit" class="wmfg_btn" name="submit" id="submit_id" value="send" />
    </li>
</ul>
</form>

PHP:

$name = $_POST['name']; 
$email = $_POST['email']; 
$title= $_POST['title']; 
$message= $_POST['message']; 
$date= date("d.m.Y"); 
$time= date("H:i:s"); 
$email_to = "myname@gmail.com"; 
$mailtext = " 
-- New message -- 
Name: $name 
Email: $email 
title: $title
date: $date
time: $time
message: $message"; 

if(isset($_POST['send']))
{
    mail($mailtext);
}

2 个答案:

答案 0 :(得分:0)

您的mail()语法不正确。

使用此mail($email_to,"My subject",$mailtext);

语法mail(to,subject,message,headers,parameters);了解详情here

您还可以使用功能丰富的电子邮件类,例如PHPMailerSwiftMailer

答案 1 :(得分:-1)

如果您不需要任何花哨的东西,只需使用mail()功能。

$name = $_POST['name']; 
$email = $_POST['email']; 
$title= $_POST['title']; 
$message= $_POST['message']; 
$date= date("d.m.Y"); 
$time= date("H:i:s"); 
$email_to = "myname@gmail.com"; 
$mailtext = " 
-- New message -- \r\n
Name: {$name}\r\n 
Email: {$email}\r\n 
title: {$title}\r\n
date: {$date}\r\n
time: {$time}\r\n
message: {$message}\r\n"; 

if($_POST['submit']))
{
    mail($to,$subject,$mailtext)
}