【问题标题】:Php Contact Form From Header [duplicate]来自标题的Php联系表[重复]
【发布时间】:2018-09-01 02:02:58
【问题描述】:

$name = htmlentities(filter_var($_POST['uname'], FILTER_SANITIZE_STRING));
    $email = htmlentities(filter_var($_POST['email'],FILTER_VALIDATE_EMAIL, FILTER_SANITIZE_EMAIL));
    $date = htmlentities(filter_var($_POST['date'],FILTER_SANITIZE_EMAIL));
    $message = htmlentities(filter_var($_POST['message'], FILTER_SANITIZE_STRING));
    $phone_number = htmlentities(filter_var($_POST['phone'],FILTER_SANITIZE_NUMBER_INT));

            $response= "<span class='text-danger'><strong>Server is busy try later</strong></span>"; $success = 0;

        $to = "<myemail>";
        $subject = "Reservation";



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

        $messageHTML = '<html><body>';
        $messageHTML .= '<h1>'.'<a href=mailto:'.$email.'>'.'Click Here To RESPOND!</a></h1>';
        $messageHTML .= '<h4>'.'Sender Name : '.$name.'</h4>';
        $messageHTML .= '<h4>'.'Sender Email : '.$email.'</h4>';
        $messageHTML .= '<h4>'.'Date : '.$date.'</h4>';
        $messageHTML .= '<h4>'.'Sender Phone Number : '.$phone_number.'</h4>';
        $messageHTML .= '<h4>'.'Message :'.'</h4>';
        $messageHTML .= '<p>'.$message.'</p>';
        $messageHTML .= '</body></html>';
        $body = $messageHTML;


        if(mail($to, $subject,$body,$headers)){         
            $success = 1;
            $response= "<span class='text-success'><strong><h1>Your Table is unconfirmed.</h1> We have received your message and we will email you confirmation within a day or two </strong></span>";
        }else{      
            $success = 0;
            $response= "<span class='text-danger'><strong>Server is busy try emailing us here: enquiries@whodcornwall.co.uk</strong></span>";
        } else{ 
          $success = 0;  
          $response= "<br><span class='text-danger><strong>Please fill all required fields.</strong></span>";
        } 
        echo json_encode(array('successs'=>$success,response'=>$response));

尝试创建一个发件人标头,因此当它发送到我的电子邮件时,它会显示“来自 $email”,但它不会让我将其更改为那个,因为表单停止工作。它目前适用于主机名电子邮件地址,但有没有办法让它适用于人们在电子邮件地址字段中写的任何内容?

【问题讨论】:

  • “表单停止工作”您需要解释一下这是什么意思。
  • 你应该把第三行中的两个过滤函数分开。
  • 使用像 phpmailerswiftmailer 这样的库,它确实为您简化了事情。

标签: php


【解决方案1】:
$to = 'mail@example.com';
$subject = 'Website Change ';
$headers = "From: " . strip_tags($_POST['req-email']) . "\r\n";
$headers .= "Reply-To: ". strip_tags($_POST['req-email']) . "\r\n";
$headers .= "CC: susan@example.com\r\n"; 
$headers .= "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/htmlcharset=UTF-8\r\n";
$message = '<p><strong>This is strong text</strong> while this is not.</p>';
mail($to, $subject, $message, $headers);

希望这对你有帮助..

【讨论】:

  • 发现我没有使用真正有帮助的回复,谢谢!
猜你喜欢
  • 2017-08-26
  • 2016-05-07
  • 2023-04-10
  • 2014-06-23
  • 2023-03-06
  • 2013-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多