2

我让它工作了一分钟,我不确定我做了什么来阻止它工作。它仍然将我带到提交时的另一个页面,但我的电子邮件绝对没有任何活动。

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

?>
4

7 回答 7

0

您好,请检查您的 mail() 是否有效。

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
}
于 2013-06-06T02:35:59.283 回答
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" );
}
?>
于 2012-07-16T01:10:46.267 回答
0

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


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

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


@Marcio Simao
Headers 不是脚本工作所必需的。它是可选参数。

于 2012-07-15T23:22:52.590 回答
0

可能是因为 HTML 如果它显示bool(true)var_dump()...

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

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

但首先使用 . 检查您的 php 代码var_dump()

于 2012-07-15T23:23:11.200 回答
0

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

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

于 2012-07-15T23:01:09.713 回答
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';
于 2012-07-15T23:13:44.930 回答
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)失败。

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

于 2012-07-15T23:14:01.727 回答