1

我能理解一些标签,我也成功地编辑了一个名为 GetSimple 的 CMS,并且一切正常(几个月前)。现在,几个月后,我已经开始使用这个并且无法通过......

我收到了发送成功的消息……“感谢您与我们联系。我们会尽快与您联系。”但我没有收到邮件。我从互联网上尝试了不同的 HTML 和 PHP 示例,但这是同样的问题。

HTML

<form method="POST" action="send.php" class="left" enctype="text/plain">
    <input type="hidden" name="form-name" value="contact" />
    <fieldset>
        <label for="your_name">YOUR NAME *</label><input type="text"  id="your_name" name="your_name" class="required" /><br/>
        <label for="your_email">YOUR email *</label><input type="text" id="your_email" name="your_email" class="required email" /><br/>
        <label for="current_site">current site</label><input type="text" id="current_site" name="current_site" /><br/>
        <label for="estimated_budget">estimated budget</label><input type="text" id="estimated_budget" name="estimated_budget" /><br/>
        <label for="project_description">project description</label> <textarea id="project_description" name="project_description"></textarea><br/>
        <!--<input type="submit" value="send" id="sendbutton">  -->
        <button class="defaultButton small" id="quotebutton"><span class="buttonLabel">Send</span></button>
    </fieldset>
</form> 

PHP 命名为“send.php”

<?php
if(isset($_POST['email'])) {


    $email_to = "mymail@gmail.com";

    $email_subject = "example subject";



    $your_name = $_POST['your_name']; // required
    $your_email = $_POST['your_email']; // required

    $error_message = "Please enter valid e-mail adress";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';

  }

    $email_message = "Form details below.\n\n";

    function clean_string($string) {
      $bad = array("content-type","bcc:","to:","cc:","href");
      return str_replace($bad,"",$string);
    }

    $email_message .= "Name: ".clean_string($your_name)."\n";
    $email_message .= "Mail: ".clean_string($your_email)."\n";
    $email_message .= "Current site: ".clean_string($current_site)."\n";
    $email_message .= "Estimated budget: ".clean_string($estimated_budget)."\n";
    $email_message .= "Project description: ".clean_string($project_description)."\n";


// create email headers
$headers = 'From: '.$your_email."\r\n".
'Reply-To: '.$your_email."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);  
?>
 } 
<!-- place your own success html below -->

Thank you for contacting us. We will be in touch with you very soon.

<?php
die();
?>
4

2 回答 2

2

根据您的脚本,提交按钮需要包含名称值“电子邮件”

<input type="submit" value="send" id="sendbutton">

所以解决方法是:

<input type="submit" value="send" name="email" id="sendbutton" />

从表单中删除 html 注释标签。完整代码:

<form method="POST" action="send.php" class="left" enctype="text/plain">
<input type="hidden" name="form-name" value="contact" />
<fieldset>
    <label for="your_name">YOUR NAME *</label><input type="text"  id="your_name" name="your_name" class="required" /><br/>
    <label for="your_email">YOUR email *</label><input type="text" id="your_email" name="your_email" class="required email" /><br/>
    <label for="current_site">current site</label><input type="text" id="current_site" name="current_site" /><br/>
    <label for="estimated_budget">estimated budget</label><input type="text" id="estimated_budget" name="estimated_budget" /><br/>
    <label for="project_description">project description</label> <textarea id="project_description" name="project_description"></textarea><br/>
    <input type="submit" name="email" value="send" id="sendbutton">
</fieldset>

于 2013-05-02T08:46:29.733 回答
2

首先我认为你缺少一些标题看看那些

// To send HTML mail, the Content-type header must be set
$headers  = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

// Additional headers
$headers .= 'To: Mary <mary@example.com>, Kelly <kelly@example.com>' . "\r\n";
$headers .= 'From: Birthday Reminder <birthday@example.com>' . "\r\n";
$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";

第二次在调用邮件函数时检查它的真假

if( mail($email_to, $email_subject, $email_message, $headers)!==true)
    {
        die('Fail to send');


    }
    die('Sucess');

    }
于 2013-05-02T11:19:22.373 回答