0

我创建了一个 PHP 文件来处理我的 jQuery 移动网站上的表单。该表格完美运行并发送电子邮件,错误工作和所有。但我不断收到来自(未知发件人)的电子邮件。主题行和电子邮件信息在那里。(来自表单的电子邮件以托管主机电子邮件地址)。感谢您提供的任何帮助。

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

// Here is the email to information

$email_to = "hostemail@email.com";
$email_subject = "Customer Service Form";
$email_from = "Company";

//error code

function died($error){
    echo "We are sorry, but there were errors found with the form you submitted.";
    echo "These errors appear bellow.<br/><br/>";
    echo $error. "<br/><br/>";
    echo "Please go back and fix these errors.<br/>";
    die();
    }
//validation

if(!isset($_POST['name']) ||
!isset($_POST['email']) ||
!isset($_POST['message'])) {
    died('We are sorry but there appears to be a problem with the form you submitted.');
}

$name = $_POST['name'];
$email = $_POST['email'];
$message = $_POST['message'];

$error_message = "";
//$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z] {2,4}$/';
//(!preg_match($email_exp, $email)) {
//$error_message .='The Email Address you entered does not appear to be valid.<br/>';
//  }

$string_exp = "/^[A-Za-z.'-]+$/";
if(!preg_match($string_exp, $name)){
    $error_message .= 'The name you entered does not seem to be valid.<br/>';   
    }

if(strlen($message) < 2) {
    $error_message .= 'The comments you entered do not appear to be valid.<br/>';
    }
if(strlen($error_message) > 0 ) {
    died($error_message);
    }

    $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 ($name) . "\n";
    $email_message .= "E-Mail:" . clean_string ($email) . "\n";
    $email_message .= "Message:" . clean_string ($message) . "\n";

    //create email headers

    $headers = 'From:' .$email_From . "\r\n" . 'Reply-To:' . $email. "\r\n" .
    'X-MAILER: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers);
    ?>

    <!-- Success Message Goes Here -->
    Thank you for contacting us. We will be in touch with you shortly. <br/>
    Please Click <a href="contact.html"> here </a> to go back to the contact page.
    <?php
}
?>
4

1 回答 1

5

标头的格式为From

Display Name <email address>

例如:

Company <foo@company.com>

现在,您只是使用“公司”,它本身既不是有效的电子邮件地址,也不是最后的电子邮件地址。

于 2012-07-23T04:22:43.400 回答