+ -
当前位置:首页 → 问答吧 → 单表php, 收不到电邮

单表php, 收不到电邮

时间:2013-03-17

来源:互联网

我做了一个单表, 客人填完后会把资料电邮给我, 及会跳出message 话畀客人知已完成订购

现在message 就睇到, 但电邮就收吾到, 请问是否出现乜问题
烦请帮忙看看, 谢

<?php
$message = "
FB 名: $_POST[fb]
Email: $_POST[email]
Remark: $_POST[remark]
Product1
Shop: $_POST[shop_a]
Item: $_POST[item_a]
Item Pic: $_POST[pic_a]
Color: $_POST[color_a]
Size: $_POST[size_a]
Quantity: $_POST[court_a]
Product2
Shop: $_POST[shop_b]
Item: $_POST[item_b]
Item Pic: $_POST[pic_b]
Color: $_POST[color_b]
Size: $_POST[size_b]
Quantity: $_POST[court_b]   
";
mb_internal_encoding("UTF-8");
mb_send_mail("[email protected], [email protected]", "客人订购清单", $message ,"From:mail");
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" c />
<meta http-equiv="refresh" c>
<title>订购完成</title>
<style type="text/css">
body,td,th {
        color: #609;        font-weight: bold;}
</style>
</head>

<body>
<p>你的订购完成!</p>
<p>我们收到后, 会在48小时内回覆报价, 谢</p>
</body>
</html>

作者: kit83831   发布时间: 2013-03-17

<?php
$message = "
FB 名: $_POST[fb]
Email: $_POST[email]
Remark: $_POST[remark]
Product1
Shop: $_POST[shop_a]
Item: $_POST[item_a]
Item Pic: $_POST[pic_a]
Color: $_POST[color_a]
Size: $_POST[size_a]
Quantity: $_POST[court_a]
Product2
Shop: $_POST[shop_b]
Item: $_POST[item_b]
Item Pic: $_POST[pic_b]
Color: $_POST[color_b]
Size: $_POST[size_b]
Quantity: $_POST[court_b]   
";

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";

if (mail("[email protected], [email protected]","客人订购清单", $message ,$headers)) {
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type"  />
<title>订购完成</title>
<style type="text/css">
body,td,th {
        color: #609;        font-weight: bold;}
</style>
</head>

<body>
<p>你的订购完成!</p>
<p>我们收到后, 会在48小时内回覆报价, 谢</p>
</body>
</html>';} else {echo 'Email send out error';}
?>

同时请留意message内的variable name有无错...

[ 本帖最后由 kary.dev 於 2013-3-17 11:26 PM 编辑 ]

作者: kary.dev   发布时间: 2013-03-17

我copy 你的
但话语法有错误!
        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
我现在可以收到email, 但就填表的资料就睇吾到吾知系咪我改左的关系

mail("[email protected], [email protected]", "客人订购清单", $message ,"From:mail");

作者: kit83831   发布时间: 2013-03-17

可能系我edit果时唔小心食左个echo....
正式的应该系
if (mail("[email protected], [email protected]","客人订购清单", $message ,$headers)) {
        echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">

$header的果段系帮你将内容encode成utf8
如果你要有sender's email的话
应该修改成

$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";
$headers .= 'From: 123<[email protected]>' . "\r\n";

至於填表的资料收唔到的话, 可以先check下呢几样
- 张form中的field name同php中是否一致, 包括大小楷
- 将message 改成
$message = '
FB 名: '.$_POST['fb'].'
Email: '.$_POST['email'].'
Remark: '.$_POST['remark'].'
Product1
Shop: '.$_POST['shop_a'].'
Item: '.$_POST['item_a'].'
Item Pic: '.$_POST['pic_a'].'
Color: '.$_POST['color_a'].'
Size: '.$_POST['size_a'].'
Quantity: '.$_POST['court_a'].'
Product2
Shop: '.$_POST['shop_b'].'
Item: '.$_POST['item_b'].'
Item Pic: '.$_POST['pic_b'].'
Color: '.$_POST['color_b'].'
Size: '.$_POST['size_b'].'
Quantity: '.$_POST['court_b'];

虽然你所写的应该都系work的, 不过我无你张form无得check fields, 所以先用返最保险的写法

作者: kary.dev   发布时间: 2013-03-18

真的想死, 搅了咁耐都未得

不过真系好多谢kary.dev的帮忙

我copy 你的code, 都系吾得

我 form code 系咁写, 因为太长, 所以我都系copy 少少出黎

<body>
<form action="mail.php" method="post" enctype="text/plain" name="form1" id="form1">
  <h2><strong><u>客人资料</u></strong> </h2>
  <p>FB 名称:
    <input name="fb" type="text" id="fb" maxlength="30" />
  (已到专页赞好者, 请提供FB 名, 否则享受不到优惠)</p>
  <p>电邮:
    <label for="email"></label>
    <input type="text" name="email" id="email" />
  </p>
  <p>备注栏:</p>
  <p>
    <label for="remark"></label>
    <textarea name="remark" id="remark" cols="45" rows="5"></textarea>
  </p>

php code 如下

<?php
$message = "
FB 名: $_POST[fb]
Email: $_POST[email]
Remark: $_POST[remark]


到底我错乜呀???
补充我form 系用dw cs6 写, 因为其实我系吾识写网页, 都系一边爬文一边写

[ 本帖最后由 kit83831 於 2013-3-18 12:08 PM 编辑 ]

作者: kit83831   发布时间: 2013-03-18

问题出错在<form action="mail.php" method="post" enctype="text/plain" name="form1" id="form1">

enctype唔可以随便用的...
将enctype="text/plain" delete左佢张form就会work的了

作者: kary.dev   发布时间: 2013-03-18