联系表格php帮助

时间:2012-01-13 04:53:57

标签: php contact

好的,我的联系表格完全正常,处理正确。我有两个问题......

  1. 在联系表单页面上,我希望添加一个复选框供用户勾选,以便将电子邮件的副本发送给他们。

  2. 在流程表单部分我想重定向到错误页面,如果一切都发生了可怕的错误。

  3. 目前在我的表单提交中,我已采取行动,转到thankyou.php

    我已经在thankyou.php页面中添加了表单流程,但如果需要,可以单独将其拉出来。

    .......................................

    我的表单流程如下(非常非常简单)

    <?php
    
    $youremail = "someonesemail@email.com";
    
    $yourname    = $_POST['yourname'];
    $email   = $_POST['email'];
    $location = $_POST['location'];
    $textarea = $_POST['textarea'];
    
     $headers = "From: $email";
    
    $content = "Hello there! This is a message from your contact form.\r\n
    \r\n
    \r\n
    Name: $yourname\r\n
    \r\n
    E-mail: $email\r\n
    \r\n
    Location: $location\r\n
    \r\n
    Message: $textarea\r\n\r\n";
    
    $send = mail($youremail, 'Message from your conatct form', $content, $headers);
    
     if($send)
     {
    echo "ok";
     }
    

    我不熟悉php所以任何帮助赞赏

3 个答案:

答案 0 :(得分:1)

如果要发送邮件副本,则需要为邮件添加适当的标题,例如:


$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= 'To: Somename <some_email@example.com>' . "\r\n";
$headers .= 'Cc: '.$yourCopyMail . "\r\n"; // this is for copy
//then
if(mail(....)) {
  echo "sent";
}
else {
  header("Location: url_to_your_error_page");
  exit;
}

答案 1 :(得分:1)

关于你的第一个问题:

This page提供了一个快速教程,介绍如何向表单添加复选框并在下一页上接收值。当您处理表单提交时,只需查看变量$_POST["checkboxname"],看看它是否设置为您给复选框的值(或者它是否完全设置了)。如果是,则只需重复命令即可发送电子邮件,并以用户的电子邮件作为收件人。

在您的情况下,它看起来像$send = mail($email, 'Message from your conatct form', $content, $headers);

我不知道如何回答你的第二个问题,因为“如果一切都发生了可怕的错误”并不是一个特别有意义的条件。

答案 2 :(得分:1)

<?php
$youremail  = "someonesemail@email.com";
$yourname   = $_POST['yourname'];
$email      = $_POST['email'];
$location   = $_POST['location'];
$textarea   = $_POST['textarea'];
$ReceiveMail= $_POST['txtReceive'];

if($ReceiveMail == "yes") {
    $content    = "";
    $headers    = "From: $email";
    @mail($email, 'Mail Notification', $content, $headers);
}
    $headers    = "From: $email";
    $content = "Hello there! This is a message from your contact form.\r\n
    \r\n
    \r\n
    Name: $yourname\r\n
    \r\n
    E-mail: $email\r\n
    \r\n
    Location: $location\r\n
    \r\n
    Message: $textarea\r\n\r\n";
    $send = mail($youremail, 'Message from your conatct form', $content, $headers);
    if($send)    {
        header("location:thankyou.php");
        exit;
    }
    else {
        header("location:error.php");
        exit;
    }
?>

我在表单中添加了一个复选框,并检查服务器端的值。 试试这个。希望它会有所帮助

相关问题