0
리눅스 서버에서 호스팅되는 내 웹 사이트에서 PHP를 사용하여 메일을 보내려면 다음 코드를 작성해야합니다. 메일이 보내지지만 메시지는 마크 업 텍스트 대신 원시 HTML로 전송됩니다. 여기 코드는 다음과 같습니다리눅스에서 PHP로 HTML 메일을 보내는 방법
<?php
sendMail('[email protected]', 'Your recovered password', 'Your password is <b>ABC123</b>', '[email protected]');
function sendMail($from='[email protected]', $subject, $message, $to = '[email protected]'){
$message = '<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>'.$subject.'</title>
</head>
<body>'.$message.'</body>
</html>';
$message = preg_replace("#(?<!\r)\n#si", "\r\n", $message);
$message = wordwrap($message, 70);
$headers = array();
$headers[] = "MIME-Version: 1.0";
$headers[] = "Content-type: text/plain; charset=UTF-8";
$headers[] = "From: $from";
$headers[] = "Reply-To: $from";
$headers[] = "Subject: {$subject}";
$additional_params = "-f $from -r $from";
if(mail($to, $subject, $message, implode("\r\n", $headers)))
echo 'Mail Sent';
else
echo 'Mail NOT Sent';
exit();
}
>
어떻게 올바르게 HTML 메일을 보낼 수있는 코드를 수정합니까?
$headers[] = "Content-type: text/html; charset=UTF-8";
이 방법을 미리
내 첫 번째 반응은 Content-type을 text/plain에서 text/html로 변경하는 것입니다. –
콘텐츠 유형은 text/plain입니까? –
@KingSkippus : 감사합니다 킹. 문제는 헤더 선언에 Content-type을 text/plain으로 사용했다는 것입니다. text/html로 변경되었습니다. –