php表单未在邮箱中提交

Posted

技术标签:

【中文标题】php表单未在邮箱中提交【英文标题】:php form is not submitting in mailbox 【发布时间】:2017-07-12 09:19:13 【问题描述】:

这是我的表单的代码

 <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  border="0">
     <tr>
       <td ><label for="name"> <span class="colored">*</span>Mr./Ms./Mrs.</label></td>
       <td ><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。仍然收到找不到页面错误 谢谢你

【问题讨论】:

尝试对此发表评论,如果 ($success) print ""; else print ""; @ÁlvaroTouzón 现在显示一个完整的空白页。 不是 404?,那么 'contactthanks.php' 或 'error.htm' 是错误,不是吗? @ÁlvaroTouzón 它在此页面上重定向我www.mysite.com/sentfrommail.php n 显示空白页面 Wahts 文件“sentfrommail.php”的内容,你能把这个: 【参考方案1】:

我浏览了你的代码。它执行完美。我收到了 404 Not found 因为我没有您要重定向到的名为 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);



?>

【讨论】:

我试过你的代码。它没有向我显示任何错误。但它也没有发送任何邮件。我给出的代码正在另一个站点上工作,除了这个。我还检查了服务器日志 n 设置。他们看起来也很好。 您的服务器必须配置为发送外发电子邮件。我假设您域的 MX 记录具有服务器传出条目。如果你在 Godaddy 上:in.godaddy.com/help/add-an-mx-record-19234 是的,它被配置为 Remote Mail Exchanger ,这就是问题所在。现在它完美地工作了。谢谢。 很高兴能帮上忙!

以上是关于php表单未在邮箱中提交的主要内容,如果未能解决你的问题,请参考以下文章

PHP表单提交失败,如何返回原值?

关于提交表单前的数字以及邮箱校检

PHP会员找回密码功能的简单实现

织梦自定义表单发送邮件超简单版(支持QQ邮箱163邮箱)

邮箱注册

表单 总结