til at sende mailen tager jeg udgangs punkt i OleBole's mail_utf8
http://www.computerworld.dk/eksperten/spm/961816?k=7937170da jeg vil sende i UTF-8 også
mail.php
<?php
//
http://www.computerworld.dk/eksperten/spm/961816?k=7937170function escapeAddr($addr) {
$check = preg_match('/(.*)<(.*)>/', $addr, $a);
if ($check) $addr = '=?UTF-8?B?'.base64_encode($a[1]).'?= <'.$a[2].'>';
return $addr;
}
//
http://www.computerworld.dk/eksperten/spm/961816?k=7937170function mail_utf8($to, $subject='Intet emne', $message='', $from='', $cc='', $bcc='', $type='plain') {
$from = escapeAddr($from);
$header = 'From: '.$from.PHP_EOL
. 'Return-Path: '.$from.PHP_EOL
. 'Reply-To: '.$from.PHP_EOL
. 'MIME-Version: 1.0'.PHP_EOL
. 'Content-type: text/'.$type.'; charset=UTF-8'.PHP_EOL
. 'X-Mailer: PHP/'.phpversion().PHP_EOL
. 'Content-Transfer-Encoding: 8bit'.PHP_EOL;
if ($cc!='') $header .= 'Cc: '.escapeAddr($cc).PHP_EOL;
if ($bcc!='') $header .= 'Bcc: '.escapeAddr($bcc).PHP_EOL;
$header .= PHP_EOL;
return mail($to, '=?UTF-8?B?'.base64_encode($subject).'?=', $message, $header);
}
?>
formular.php ( kunne godt være formular.html, da der ikke er noget php i coden)
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>demo</title>
</head>
<body>
<form action="send_mail.php" method="post">
<input type="text" name="email" placeholder="din mail addresse"><br>
<input type="text" name="dato" placeholder="test dato"><br>
<input type="submit" value="send">
</form>
</body>
</html>
send_mail.php
<?php
require_once("mail.php");
if(isset($_POST['email'])) {
$viderestil = "svar.htm";
$email = $_POST['email'];
$date = $_POST['dato'];
$subject = 'test';
$message = "æ bæ bu ÆØÅ æøå,\r\njeg har danske bogstaver, du har booket ". $date. " til testen";
$from = 'musikken <info@musikken.dk>';
$sent = @mail_utf8($email, $subject, $message, $from);
if ($sent) {
header("Location: $viderestil");
exit(0);
}
else{
echo header("Location: fejl.html");
exit(1);
}
}
?>
svar.htm
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>tak</title>
</head>
<body>
tak for Deres mail, vi kigger på den<br>
med venlig hilsen<br>
ÆØÅæøå
</body>
</html>
jeg ville nok slå formular.php og send.mail.php sammen til en fil
<?php
require_once("mail.php");
if(isset($_POST['email'])) {
$viderestil = "svar.htm";
$email = $_POST['email'];
$date = $_POST['dato'];
$subject = 'test';
$message = "æ bæ bu ÆØÅ æøå,\r\njeg har danske bogstaver, du har booket ". $date. " til testen";
$from = 'musikken <info@musikken.dk>';
$sent = @mail_utf8($email, $subject, $message, $from);
if ($sent) {
header("Location: $viderestil");
exit(0);
}
}
?>
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>demo</title>
</head>
<body>
<?php
if(isset($sent)){
echo "Åå nej, der er sket en fejl ved afsendelse af mailen";
}
else{
?>
<form action="<?php echo $_SERVER["PHP_SELF"]; ?>" method="post">
<input type="text" name="email" placeholder="din mail addresse"><br>
<input type="text" name="dato" placeholder="test dato"><br>
<input type="submit" value="send">
</form>
<?php
}
?>
</body>
</html>