作者non036 (Taiwan獼猴)
看板PHP
標題[請益] php抓不到變數?
時間Thu Mar 22 16:30:56 2007
之前有人放一個壓縮檔,用PHP連Gmail寄信~
可是連續試了好幾次,收到的信都是空白的,變數加上$_POST['']也沒用
有人可以幫我抓Bug嗎?
以下是表單<u4.html>
-------------------------------------------------------------
<html xmlns="
http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>報名系統</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body bgcolor="#C0DFFD"><center>
<form action="mail.php" method="post" name="mail">
<table border="0">
<tr>
<td><table border="1" bordercolor="#999999">
<tr>
<td><div align="center"><span class="style12">姓名</span></div></td>
<td><input type="text" name="name" /></td>
</tr>
<tr>
<td><div align="center"><span class="style12">服務單位</span></div></td>
<td><input type="text" name="job" /></td>
</tr>
<tr>
<td><div align="center"><span class="style12">職稱</span></div></td>
<td><input type="text" name="title" /></td>
</tr>
<tr>
<td><div align="center"><span class="style12">餐點</span></div></td>
<td><input name="food" type="radio" value="葷" />
<span class="style8">葷</span>
<input name="food" type="radio" value="素" />
<span class="style8">素</span></td>
</tr>
</table>
<p align="center">
<input type="submit" name="Submit" value="送出" />
<input type="reset" name="Reset" value="清除" />
</p></td>
</tr>
</table>
</form></center>
</body>
</html>
-----------------------------------------------------------------
以下是<mail.php>
-----------------------------------------------------------------
<?
require("libgmailer.php");
$gmail_acc = "@gmail.com";
$gmail_pwd = "XXX";
$my_timezone = "GMT +08:00";
$gmailer = new GMailer();
if ($gmailer->created) {
$gmailer->setLoginInfo($gmail_acc, $gmail_pwd, $my_timezone);
// $gmailer->setProxy("proxy.company.com");
if ($gmailer->connect()) {
// GMailer connected to Gmail successfully.
// Do something with it.
$to = "@gmail.com";
$subj = "報名表";
$name=$_POST['name']; ←有試過雙引號,還是沒抓到變數
$job=$_POST['job'];
$title=$_POST['title'];
$food=$_POST['food'];
$body ="姓名:$name \n
服務單位:$job \n
職稱:$title \n
餐點:$food \n";
$gmailer->send($to, $subj, $body, $cc="", $bcc="", $mid="", $tid="",
$files=0, $draft=false, $orig_df="", $is_html=0, $from="", $attachments =
array());
} else {
die("Fail to connect because: ".$gmailer->lastActionStatus()."\n");
}
} else {
die("Failed to create GMailer because: ".$gmailer->lastActionStatus()."\n");
}
?>
<html xmlns="
http://www.w3.org/1999/xhtml">
<head>
<title>傳送完畢</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
</style>
</head>
<body bgcolor="#C0DFFD" class="pageName">
感謝您花時間填寫資料…
</body>
</html>
--------------------------------------------------------------------------
--
┬─┬─┬─████◣ ┌─┬─┬┬─┬─╭────────────╮┬
██
┴┬ ◣┴┬ ◢ ◥▌ ├─ ◢██◣┴┬│你偷吃, 鄭先生有看到。│┴
◢
─┴ 洨 ┬┴◢◤□︵□▌+ ├┬:█: ◥▌┴╰────────────╯┬
◢◤
─┬ ㊣ ┴┬◤ ╰ ◤
├ ∴ ︰□︵□▌┬┴┬┴┬┴┬─┬┴┬ made by ◤
┬┴┬─┬┴ ◢▼ ├┬┴◥ )●◤▅┴┬┴┬┴┬┴┬┴┬┴ orz ◢
┴┬┴┬┴┬◢◤ ├┴┬◢ │◣◤┬┴─┴┬┴─┴┬┴┬ ⊙Ptt ◢◤
--
※ 發信站: 批踢踢實業坊(ptt.cc)
◆ From: 220.141.7.241
※ 編輯: non036 來自: 220.141.7.241 (03/22 16:32)
1F:推 shadowjohn:name 好像是保留字,用別的看看 XD 03/22 17:42
2F:→ non036:改成$user_name也是一樣,試了一下~ 03/22 17:48
3F:推 shadowjohn:<input type="text" name="name" /> --> 這也要改... 03/22 17:52
4F:推 non036:有!所變數都加上"user_",一樣空白信! 03/22 17:53
5F:推 kyowinner:$body內容的變數都加上單引號看看 03/22 21:07
6F:推 buganini:你不應該看信件吧...先用echo看看變數到底收到沒 03/22 21:28
7F:→ buganini:如果有的話那就是gmailer的使用問題了 03/22 21:28
8F:推 non036:好!我先試試看~ 03/22 21:33
9F:推 non036:確認,變數沒有擷取到,有問題? 03/22 21:36
10F:推 non036:為什麼抓不到變數 = =?誰來告訴我阿 @_@ 03/22 23:17
11F:推 KiroKu:你是不是多了個</table> 我眼睛好花@@ 03/23 00:13
12F:→ KiroKu:我找到了.. 03/23 00:15
13F:→ KiroKu:你有開magic_quote嗎? 03/23 00:17
14F:推 non036:好問題!伺服器不是我架的,是學校的~!明天問問看! 03/23 00:38
15F:→ non036:因該沒有多加</table>,用Dreamweaver編輯完再改的,應該沒 03/23 00:39
16F:→ non036:問題才對。 03/23 00:41
17F:→ non036:Dreamweaver有DeBug功能吧!PHP用筆記簿寫的,也許有Bug! 03/23 00:42
18F:推 non036:恩!magic_quote是關閉的 03/23 17:02
19F:推 windincloud:if ($gmailer->created) <= 是$gmailer->created()嗎? 03/27 23:43