联系表格没有发送

时间:2012-07-15 22:53:07

标签: php html sendmail

我让它工作了一分钟,我不知道我做了什么来阻止它工作。它仍然需要我在提交的另一页,但我的电子邮件绝对没有活动。

HTML

<form id="contact_form" action="sendemail.php" method="post">
    <p><label>Name:<br />
        <input type="text" name="name" class="textfield" value="" />
    </label></p>

    <p><label>Email: <br />
         <input type="text" name="email" class="textfield" value="" />
    </label></p>

    <p><label>Phone Number: <br />
        <input type="text" name="phone" class="textfield" value="" />
    </label></p>

    <p><label>Detail: <br />
        <textarea name="detail" class="textarea" cols="45" rows="5"></textarea>
    </label></p>

    <p><input type="submit" name="submit" class="button" value="Submit" /></p>
</form>

PHP

<?php 
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$detail = $_REQUEST['detail'];

$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail" ;

mail( "myemail@gmail.com", "You have recieved a message", "Information Requested:\n\n$message", "From: $email") ;

header( "location: http://mywebsite.com/thanks.html" );

?>

7 个答案:

答案 0 :(得分:0)

许多服务器都有I / O电子邮件限制。在尝试代码时,它曾经发生过一次。也许只是这个或 - 正如Austin所说 - 也许邮件被发送到你电子邮件地址的垃圾邮件文件夹。

尝试检查您的网络服务器日志,看它是否包含更多信息。

答案 1 :(得分:0)

您应该定义标题并进行一些改进,尝试使用此代码:

// As you know that you form uses POST method, you can use $_POST instead of $_REQUEST
$name   = $_POST['name'];
$email  = $_POST['email'];
$phone  = $_POST['phone'];
$detail = $_POST['detail'];

// Headers
$headers  = "From: =?utf-8?B?".base64_encode ('Sender Name')."?= <sender@email.com>\r\n";
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=utf-8\r\n";

// As the content is HTML, you shoud use <br /> instead of \n to break line
$message = "Name: $name<br />Email: $email<br />Phone Number: $phone<br />Detail: $detail" ;

// Trying to send the message
if ( mail('to@email.com', "=?utf-8?B?".base64_encode('Message subject')."?=", $message, $headers) )
    header( "location: http://mywebsite.com/thanks.html" );
else
    echo 'Message fail';

答案 2 :(得分:0)

检查您的垃圾邮件/垃圾邮件文件夹。如果消息不存在,请尝试以下代码:

<?php
$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$detail = $_REQUEST['detail'];

$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail" ;

var_dump( mail( "myemail@gmail.com", "You have recieved a message", "Information Requested:\n\n$message", "From: $email") );

//header( "location: http://mywebsite.com/thanks.html" );
?>

如果邮件成功发送,它将返回bool(true),否则如果失败则会返回bool(false)

另外,请确保电子邮件地址正确无误......

答案 3 :(得分:0)

你有任何错误吗?使用ini_set('display_errors', true)并查看。


您应该将$_REQUEST更改为$_POST,因为当您不知道来自(GET,POST或COOKIE)的数据时,应使用$_REQUEST。我们看到来自POST的数据,因为您将表单的方法指定为POST。

您还应该检查是否使用isset()empty()设置了这些变量。


@ Marcio Simao
脚本不是必需的标头。它是可选参数。

答案 4 :(得分:0)

可能是因为HTML会在bool(true)中向您显示var_dump() ...

尝试从标签中输出您的输入字段...通常标签用于即将到来的字段..不要将字段放在标签标签下......就像这样:

<p><label>Name:<br />
    <input type="text" name="name" class="textfield" value="" />
</label></p>

但请先使用var_dump()检查您的php代码。

答案 5 :(得分:0)

你可以使用

<?php    
if(isset($_POST['submit'])){    
$name = $_POST['name'];
... other info
$message = "Name: $name\nEmail: $email\nPhone Number: $phone\nDetail: $detail";
mail( "myemail@gmail.com", "You have recieved a message", "Information Requested:\n\n$message", "From: $email") ;
   header( "location: http://mywebsite.com/thanks.html" );
}
?>

答案 6 :(得分:0)

嗨请检查你的邮件()是否有效。

if(mail($to, $subject, $message, $headers)){
  // Working
}

如果不善意做邮件功能的标准格式

$name = $_REQUEST['name'];
$email = $_REQUEST['email'];
$phone = $_REQUEST['phone'];
$detail = $_REQUEST['detail'];


$subject = "Subject";
$headers = "From: \"".$youremail." ".$youremail."\" <".$youremail.">\n"; 
$headers .= "To: \"".$email."\" <".$email.">\n"; 
$headers .= "Return-Path: <".$email.">\n";
$headers .= "MIME-Version: 1.0\n";
$headers .= "Content-Type: text/HTML; charset=ISO-8859-1\n";    

$message = "Your Message here!";

if(mail($to, $subject, $message, $headers)){
   // success
}