請問錯在哪呢 謝謝幫忙?

2018-08-01 5:21 pm
2 <html>
13 <head>
14 <meta charset="UTF-8">
15 <title>聯絡表單</title>
16 </head>
17 <body>
18 <?php if(isset($_POST["sendmail"]) && ($_POST["sendmail"]=="true")){?>
19 寄送成功,<a href="php_formtomail.php">再寄一次</a>。
20 <?php }else{?>
21 <form name="form1" method="post" action="">
22 <table border="0" cellpadding="4" cellspacing="0">
23 <tr>
24 <td>寄件人姓名</td>
25 <td><input type="text" name="fromname" id="fromname"></td>
26 </tr>
27 <tr>
28 <td>寄件人郵件</td>
29 <td><input type="text" name="frommail" id="frommail"></td>
30 </tr>
31
32 <tr>
33 <td>主旨</td>
34 <td><input type="text" name="mailsubject" id="mailsubject"></td>
35 </tr>
36 <tr>
37 <td colspan="2"><textarea name="mailcontent" id="mailcontent" cols="45" rows="5"></textarea></td>
38 </tr>
39 <tr>
40 <td colspan="2"><input type="submit" name="button" id="button" value="送出">
41 <input name="sendmail" type="hidden" id="sendmail" value="true"></td>
42 </tr>
43 </table>
44 </form>
45 <?php }?>
46 </body>
47 </html>
更新1:

1 <?php 2 if(isset($_POST["sendmail"]) && ($_POST["sendmail"]=="true")){ 3 $mailFrom="=?UTF-8?B?" . base64_encode($_POST["fromname"]) . "?= <".$_POST["frommail"].">"; 4 $mailto="[email protected]"; 5 $mailSubject="=?UTF-8?B?" . base64_encode($_POST["mailsubject"]). "?="; 6 $mailHeader="From:".$mailFrom."\r\n"; 7 $mailHeader.="Content-type:text/html;charset=UTF-8"; 8 mail($mailto,$mailSubject,$_POST["mailcontent"],$mailHeader); 9 } 10 ?>

更新2:

請問哪裡有錯? 1 <?php 2 if(isset($_POST["sendmail"]) && ($_POST["sendmail"]=="true")){ 3 $mailFrom="=?UTF-8?B?" . base64_encode($_POST["fromname"]) . "?= <".$_POST["frommail"].">"; 4 $mailto="[email protected]"; 5 $mailSubject="=?UTF-8?B?" . base64_encode($_POST["mailsubject"]). "?="; 6 $mailHeader="From:".$mailFrom."\r\n"; 7 $mailHeader.="Content-type:text/html;charset=UTF-8"; 8 mail($mailto,$mailSubject,$_POST["mailcontent"],$mailHeader); 9 } 10 ?>

回答 (1)

2018-08-10 9:58 pm
<html>
<head>
<meta charset="UTF-8">
<title>聯絡表單</title>
</head>
<body>
<?php if(isset($_POST["sendmail"]) && ($_POST["sendmail"]=="true")){
$mailFrom="=?UTF-8?B?" . base64_encode($_POST["fromname"]) . "?= <".$_POST["frommail"].">";
$mailto="[email protected]";
$mailSubject="=?UTF-8?B?" . base64_encode($_POST["mailsubject"]). "?=";
$mailHeader="From:".$mailFrom."\r\n";
$mailHeader.="Content-type:text/html;charset=UTF-8";
mail($mailto,$mailSubject,$_POST["mailcontent"],$mailHeader);
echo '寄送成功,<a href="1.php">再寄一次</a>。';
}else{
echo
'<form name="form1" method="post" action="">
<table border="0" cellpadding="4" cellspacing="0">
<tr>
<td>寄件人姓名</td>
<td><input type="text" name="fromname" id="fromname"></td>
</tr>
<tr>
<td>寄件人郵件</td>
<td><input type="text" name="frommail" id="frommail"></td>
</tr>
<tr>
<td>主旨</td>
<td><input type="text" name="mailsubject" id="mailsubject"></td>
</tr>
<tr>
<td colspan="2"><textarea name="mailcontent" id="mailcontent" cols="45" rows="5"></textarea></td>
</tr>
<tr>
<td colspan="2"><input type="submit" name="button" id="button" value="送出">
<input name="sendmail" type="hidden" id="sendmail" value="true"></td>
</tr>
</table>
</form>';
}?>
</body>
</html>
參考: [PHP]解決寄件者名稱與信件標題亂碼問題 https://sofree.cc/php-base64-utf8/ Using UTF-8 characters on an e-mail subject https://ncona.com/2011/06/using-utf-8-characters-on-an-e-mail-subject/


收錄日期: 2021-04-26 15:42:25
原文連結 [永久失效]:
https://hk.answers.yahoo.com/question/index?qid=20180801092115AAHXfTh

檢視 Wayback Machine 備份