我有一个html文件(index.html),加载后会在5秒后调用一个颜色框。 colorbox打开另一个html文件(popup.html),其中有一个表单供用户提交详细信息。
在提交表单时调用生成并发送电子邮件的php文件。发送后,popup.html会显示成功消息。
// 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);
?>
<!-- success html -->
<div class="popup_message"><h2>Thank you for contacting us. We will be in touch with you very soon.</h2></div>
<?php
}
die();
?>
我遇到的问题是我试图使用全局CSS文件(在index.html和popup.html中定义)来设置popup_message H2元素的样式,但是它不会对输出进行样式设置。
我还需要在php文件中定义文件吗?
这是我的php文件,我尝试在DIV周围添加HTML代码,但这只是阻止了显示成功消息:
<?php
echo
if(isset($_POST['email'])) {
$mobile_error = "";
$email_to = "contactus@complete-models.com";
$email_subject = "7 Day free pass interest";
function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
echo "Please go back and fix these errors.<br /><br />";
die();
}
// validation expected data exists
if( !isset($_POST['first_name']) || !isset($_POST['mobile']) || !isset($_POST['email']) ) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}
$first_name = $_POST['first_name']; // required
$mobile = $_POST['mobile']; // required
$email_from = $_POST['email']; // 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 />';
}
$mobile_exp = '[0-9]';
if(!preg_match($mobile_exp, $mobile)) {
$error_message .= 'The Mobile number you entered does not appear to be valid.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$first_name)) {
$error_message .= 'The Name you entered does not appear to be valid.<br />';
}
$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($first_name)."\n";
$email_message .= "Mobile: ".clean_string($mobile)."\n";
$email_message .= "Email: ".clean_string($email_from)."\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);
?>
<!-- success html below -->
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" type="text/css" href="css/screen_style.css" />
</head>
<body>
<div class="popup_message"><h2>Thank you for contacting us. We will be in touch with you very soon.</h2></div>
</body>
</html>
<?php
}
die();
?>
答案 0 :(得分:0)
是的,您还需要在PHP文件中定义CSS。实际上,PHP文档应该包含完全形成的HTML,也就是说它应该包括:<html>
,<head>
和<body>
标记。
这是因为PHP文件是它自己的单独文件,就像index.html和popup.html一样。