php表单没有在邮箱中提交

时间:2017-07-12 09:19:14

标签: php forms post submission

这是我表单的代码

 <form name="contactform" method="post" action="sentfrommail.php">
  <h1 style="color: #000; font-size:18px; text-decoration:underline; text-align:left; padding-bottom:5px;"> Personal Details</h1>


   <table width="90%" border="0">
     <tr>
       <td width="40%"><label for="name"> <span class="colored">*</span>Mr./Ms./Mrs.</label></td>
       <td width="60%"><input  type="text" name="name" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Designation:</label></td>
       <td><input  type="text" name="desg" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Company Name:</label></td>
       <td><input  type="text" name="compname" maxlength="50" size="40%"></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Address:</label></td>
       <td> <textarea  name="address" maxlength="1000" cols="42" rows="2"></textarea></td>
     </tr>
     <tr>
       <td><label for="name"><span class="colored">*</span>Email:</label></td>
       <td><input  type="text" name="email" maxlength="80" size="40%"></td>
     </tr>

   </table>



       <div class="center" style="padding-left:20%; padding-top:4%;">                     
       <button class="button2" name="submit" type="submit" value="Submit"><span>Send Message</span></button>
      </div>   
  </form>      

sentfrommail.php在下面给出

    <?php

$EmailFrom = "mymail@site.com";
$EmailTo = "editor@mysite.com";
$Subject = "New Enquiry";
$name = Trim(stripslashes($_POST['name'])); 
$desg = Trim(stripslashes($_POST['desg'])); 
$compname = Trim(stripslashes($_POST['compname'])); 
$address = Trim(stripslashes($_POST['address'])); 
$email = Trim(stripslashes($_POST['email'])); 



// validation
$validationOK=true;
if (!$validationOK) {
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
  exit;
}

// prepare email body text
$Body = "";
$Body .= "Name: ";
$Body .= $name;
$Body .= "\n";
$Body .= "Designation: ";
$Body .= $desg;
$Body .= "\n";
$Body .= "Company Name: ";
$Body .= $compname;
$Body .= "\n";
$Body .= "Email: ";
$Body .= $email;
$Body .= "\n";
$Body .= "Address: ";
$Body .= $address;
$Body .= "\n";

$Body .= "\n";

// send email 
$success = mail($EmailTo, $Subject, $Body, "From: <$EmailFrom>");

// redirect to success page 
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=contactthanks.php\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.htm\">";
}
?>

表单未提交。 它显示404页面未找到错误。我做错了什么?

我也使用过这种方法

    <?PHP
/*
    Contact Form from HTML Form Guide
    This program is free software published under the
    terms of the GNU Lesser General Public License.
    See this page for more info:

*/
require_once("http://www.example.com/include/fgcontactform.php");

$formproc = new FGContactForm();


//1. Add your email address here.
//You can add more than one receipients.
$formproc->AddRecipient('editor@mysite.com'); //<<---Put your email address here


//2. For better security. Get a random tring from this link: 
// and put it here
$formproc->SetFormRandomKey('CnRrspl1FyEylUj');


if(isset($_POST['submitted']))
{
   if($formproc->ProcessForm())
   {
        $formproc->RedirectToURL("thank-you.php");
   }
}

?>

并且fgcontactform.php包含phpmailer。仍然没有找到页面错误 谢谢

1 个答案:

答案 0 :(得分:0)

我查看了你的代码。它完美地执行。我找到了404找不到,因为我没有一个名为contactthanks.php的页面,你正在重定向到。

以下是发送电子邮件的示例代码:

<?php
$error=''; // Variable To Store Error Message
// Define $username and $password
$name=$_POST['name'];

$email=$_POST['email'];

$designation=$_POST['designation'];

$companyName=$_POST['companyName'];

$address=$_POST['address'];

sendEmail($email,$name,$company,$designation,$companyName,$address);
header( "Refresh:2; url=../index.php", true, 303);
mysqli_close($connection);

function sendEmail($email,$enquiryID,$name,$company,$sub) 
{
    $to = $email; // If you want the user to get the email then make no changes otherwise change this email to the Email ID you want to send an email to.

    $subject = 'Welcome to Your Application';

    $headers = "From: " . "Your Company Name<noreply@domain.com>" . "\r\n"; // Please make sure you have an active email id you add here instead of "noreply@domain.com" which has the MX records indexed to your hosting.
    // The idea is that you should be able to send an email from the hosting server via your domain.

    $headers .= "MIME-Version: 1.0\r\n";

    $headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";


    $message = '
                    <b>Name : </b>'.$name.'<br>
                    <b> Company : </b>'.$company.'<br>
                    <b> Email : </b>'.$email.'<br>
                    <b> Address : </b>'.$address.'<br><br>
                    <b> Designation : </b'.$designation.' <br>
    ';
    mail($to, $subject, $message, $headers);
}


?>