PDA

View Full Version : مشکل در فرم PHP



پیام حیاتی
دوشنبه 20 شهریور 1391, 23:07 عصر
سلام
مشکل اینه که بعد از ارسال به ایمیل محتویات ارسال نمیشن و اخطار Syntax (گرامر) میده؟
فرم ساخته شده (http://www.payam-hayati.ir/contact.php)

کدهای فایل HTML :


<!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" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>
<table width="400" border="0" align="center" cellpadding="3" cellspacing="1">
<tr>
<td><strong>Contact Form </strong></td>
</tr>
</table>

<table width="400" border="0" align="center" cellpadding="0" cellspacing="1">
<tr>
<td><form name="form1" method="post" action="send_contact.php">
<table width="100%" border="0" cellspacing="1" cellpadding="3">
<tr>
<td width="16%">Subject</td>
<td width="2%">:</td>
<td width="82%"><input name="subject" type="text" id="subject" size="50"></td>
</tr>
<tr>
<td>Detail</td>
<td>:</td>
<td><textarea name="detail" cols="50" rows="4" id="detail"></textarea></td>
</tr>
<tr>
<td>Name</td>
<td>:</td>
<td><input name="name" type="text" id="name" size="50"></td>
</tr>
<tr>
<td>Email</td>
<td>:</td>
<td><input name="customer_mail" type="text" id="customer_mail" size="50"></td>
</tr>
<tr>
<td>&nbsp;</td>
<td>&nbsp;</td>
<td><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Reset"></td>
</tr>
</table>
</form>
</td>
</tr>
</table>
</body>
</html>


کدهای فایل PHP :


<!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" content="text/html; charset=utf-8" />
</head>

<body>
<?php

// Contact subject
$subject ="$subject";

// Details
$message="$detail";


// Mail of sender
$mail_from="$customer_mail";

// From
$header="from: $name <$mail_from>";


// Enter your email address
$to ='ahvazsell@gmail.com';

$send_contact=mail($to,$subject,$message,$header);


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
</body>
</html>


تشکر.

tehro0n
دوشنبه 20 شهریور 1391, 23:17 عصر
ابتدای کار دیدم که متغیرهاتو با دستور get نمی گیری، این را اصلاح کن اگه باز کار نکرد پیغام بگذار دوباره ببینم چی به چیه


$subject ="$subject";

باید بشه

$subject = $_GET['subject'];


البته در مراتب بعد یکم کاربر رو باید محدود کنی که هرچیزی وارد نکنه
یکی از راه ها اینه که موقع ارسال تابع رو انکد کنی


encodeURIComponent(subject)

بعد موقعی که می خوای بگیری اینجوری بگیری



urldecode($_GET['subject'])

پیام حیاتی
سه شنبه 21 شهریور 1391, 00:57 صبح
مغیرها رو به طبق فرمایشتون تغییر دادم اما تغییری حاصل نشد.

tehro0n
سه شنبه 21 شهریور 1391, 01:49 صبح
اون هدر رو به این شکل تغییر بدید، فرمان POST رو هم GET کنید و یا هنگام گرفتن به جای GET بنویسید POST



$newLine = "\r\n"; //var just for newlines
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . $newLine;
$headers .= 'Content-type: text/html; charset=utf-8' . $newLine;
$headers .= 'From: Name TARAF<'.$from.'>' . $newLine;
$headers .= 'To: Payam Hayati <'.$to.'>' . $newLine;
//$headers .= 'Cc: birthdayarchive@example.com' . "\r\n";
//$headers .= 'Bcc: birthdaycheck@example.com' . "\r\n";
$headers .= 'Reply-To: '.$from . $newLine;


هر کدام از مورد ها رو هم نخواستید حذف کنید
در مورد enCode کردن هم اون نمونه جاوا بود و اینجا نمیشه انجام داد، با ای جکس اگه اطلاعات رو بفرستید اون کار خوبیه

اگر error داد پیغام آن را بفرمایید
و کاری را هم که ادیت کردید بگذارید ببینم درست انجام شده یا نه
موفق باشید

پیام حیاتی
سه شنبه 21 شهریور 1391, 11:03 صبح
همچنان خطای تصویر (1) وجود داره :
کدهای فایل send_contact.php :


<!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" content="text/html; charset=utf-8" />
</head>

<body>
<?php

// Contact subject
$subject = $_GET["$subject"];

// Details
$message = $_GET["$detail"];


// Mail of sender
$mail_from = $_GET["$customer_mail"];

// From
$newLine = "\r\n"; //var just for newlines
// To send HTML mail, the Content-type header must be set
$headers = 'MIME-Version: 1.0' . $newLine;
$headers .= 'Content-type: text/html; charset=utf-8' . $newLine;
$headers .= 'From: Name TARAF<'.$from.'>' . $newLine;
$headers .= 'To: Payam Hayati <'.$to.'>' . $newLine;
$headers .= 'Reply-To: '.$from . $newLine;

$header="from: $name <$mail_from>";


// Enter your email address
$to ='payam.hayati@yahoo.com';

$send_contact=mail($to,$subject,$message,$header);


// Check, if message sent to your email
// display message "We've recived your information"
if($send_contact){
echo "We've recived your contact information";
}
else {
echo "ERROR";
}
?>
</body>
</html>

tehro0n
سه شنبه 21 شهریور 1391, 22:09 عصر
آقا من گفتم اینطوری بشه

$subject = $_GET['subject'];

اون وقت شما اینجوری گذاشتی که!

$subject = $_GET["$subject"];

پیام حیاتی
چهارشنبه 22 شهریور 1391, 11:20 صبح
کاملا" درسته متوجه شدم.
من با متد POST یک سری متغیر رو پاس میدادم به فرم ولی تو فرم اونها رو نمیگیرفتم که بدم برای ارسال به ایمیل.
برای متغیرها به شکل گفته شده تغییرات رو اعمال کردم و فرم درست شد،البته با همون سوپرگلوبال POST .
بسیار ممنون.