2011-09-09 10 views
0

저는 Stackoverflow를 처음 접했습니다. 멋진 문제에 대한 첫 번째 문제가 생겼다고 생각했습니다.PHP 폼을위한 HTML 출력

HTML 템플릿으로 넣어야하는 PHP Form이 있습니다. 성공 메시지는 정상적으로 처리됩니다. 그러나 이메일을 통해 전송되는 메시지는이를 수행하지 않습니다. 여기에 내 코드 예제가있다. 양식은 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 protected]"; // required 
// $telephone = $_POST['telephone']; // not required 
// $comments = $_POST['comments']; // required 

$error_message = ""; 
$email_exp = '/^[A-Za-z0-9._%-][email protected][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 
} 
?> 

답변

1

당신은 당신의 헤더 상쇄하고 : 다음

$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 개를 함께 연결합니다. r 코드를 사용하면 $ 헤더를 두 번째 할당으로 바꿉니다.

+0

답장을 보내 주신 Kevin에게 감사드립니다. 나는 그것을 시도하고 출력은 "이것은의 이다. 그것은 단어를 대담하게하지 않습니다. 어떤 제안? –