doupin8555 2012-07-23 04:11
浏览 14
已采纳

未知发件人PHP(内部代码)

I've created a PHP file to work with my form on my jQuery mobile site. The form works perfectly and sends the email and errors work and all. But I keep getting the email from an (unknown sender). Subject line and email information is there. (Email coming from the form to host the host email address). Thanks for any help that can be provided.

<?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. 

";

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

    $email_message .= "Name:" . clean_string ($name) . "
";
    $email_message .= "E-Mail:" . clean_string ($email) . "
";
    $email_message .= "Message:" . clean_string ($message) . "
";

    //create email headers

    $headers = 'From:' .$email_From . "
" . 'Reply-To:' . $email. "
" .
    '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
}
?>
  • 写回答

1条回答 默认 最新

  • dreamlife2014 2012-07-23 04:22
    关注

    The format for the From header is:

    Display Name <email address>
    

    For example:

    Company <foo@company.com>
    

    Right now, you're just using "Company", which is neither a valid e-mail address on its own, nor has an e-mail address at the end.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 企业资源规划ERP沙盘模拟
  • ¥15 树莓派控制机械臂传输命令报错,显示摄像头不存在
  • ¥15 前端echarts坐标轴问题
  • ¥15 CMFCPropertyPage
  • ¥15 ad5933的I2C
  • ¥15 请问RTX4060的笔记本电脑可以训练yolov5模型吗?
  • ¥15 数学建模求思路及代码
  • ¥50 silvaco GaN HEMT有栅极场板的击穿电压仿真问题
  • ¥15 谁会P4语言啊,我想请教一下
  • ¥15 这个怎么改成直流激励源给加热电阻提供5a电流呀