繁体   English   中英

php表单的HTML输出

[英]HTML Output for a php form

我是Stackoverflow的新手,并认为我将第一期带给您的好人。

我有一个PHP表单需要作为HTML模板输出。 成功消息可以做到这一点。 但是通过电子邮件发送的消息无法执行。 这是我的代码示例。 除HTML输出外,该表单运行良好。 我在其中放置了标签以查看其是否有效,但标签无法转换。

任何帮助将不胜感激。

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

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = ($_POST['email']);
$email_subject = "Dear ".($_POST['first_name']). ", someone you know sent you this      email.";


function died($error) {
    // your error code can go here
    echo "<h4>We are very sorry, but you left a field blank or incorrect. </h4>";
    echo "Maybe you need to be slapped.<br /><br />";
    echo $error."<br /><br />";
    echo "Please press the back button to resend redo.<br /><br />";
    die();
}

// validation expected data exists
if(!isset($_POST['first_name']) // ||!isset($_POST['last_name'])
     ||!isset($_POST['email'])
     //||!isset($_POST['telephone'])
     //||!isset($_POST['comments'])
    ) {
    died('We are very sorry, but left a field blank or incorrect.');       
}

$first_name = $_POST['first_name']; // required
// $last_name = $_POST['last_name']; // required
$email_from = "email@domain.com"; // required
// $telephone = $_POST['telephone']; // not required
// $comments = $_POST['comments']; // required

$error_message = "";
$email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
if(!preg_match($email_exp,$email_from)) {
$error_message .= 'The Email Address you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
 if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The First Name you entered does not appear to be valid.<br />';
}
// if(!preg_match($string_exp,$last_name)) {
// $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
// }
// if(strlen($comments) < 2) {
//  $error_message .= 'The Comments you entered do not appear to be valid.<br />';
// }
if(strlen($error_message) > 0) {
died($error_message);
}
    // Set the Headers for HTML E-mail
    $headers  = 'MIME-Version: 1.0' . "\r\n";
    $headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";


// email message sent to the person getting slapped
$email_message = "Someone has just sent you an email.\n\n";



 function clean_string($string) {


  $headers = "Content-Type: text/html; charset=iso-8859-1\n";
  $email_message = "  This is a test <strong> of the HTML </strong>";

 }
 $email_message = "  This is a test <strong> of the HTML </strong>";







 // $email_message .= "First Name: ".clean_string($first_name)."\n";
 // $email_message .= "Last Name: ".clean_string($last_name)."\n";
 //  $email_message .= "Email: ".clean_string($email_from)."\n";
 //  $email_message .= "Telephone: ".clean_string($telephone)."\n";
 //  $email_message .= "Comments: ".clean_string($comments)."\n";


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

<!-- include your own success html here -->

Thank you for sending your <strong>email</strong>. <br />

Please press the back button



<?php
}
?>

您要取消标题:

$headers = "Content-Type: text/html; charset=iso-8859-1\n";

那么你有:

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers); 

而是尝试:

$headers = "Content-Type: text/html; charset=iso-8859-1\n";

$headers .= 'From: '.$email_from."\r\n".
    'Reply-To: '.$email_from."\r\n" .
    'X-Mailer: PHP/' . phpversion();
    @mail($email_to, $email_subject, $email_message, $headers); 

$ headers变量的第二个赋值中的。=将2串联在一起,在您的代码中,您将$ headers替换为第二个赋值。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM