PDA

View Full Version : سوال: درخواست فایل PHP برای ارسال فرم



Over Lord 238
یک شنبه 02 فروردین 1394, 02:01 صبح
سلام!

کسی میتونه یه قطعه کد PHP اینجا ثبت کنه که اطلاعات این فرم رو به ایمیل ارسال کنه و پیام اطلاعات ثبت شد رو نمایش بده.؟



<!-- Form -->
<form method="post" class="my-form" action="php/process.php">
<input type="text" name="email" class="email" value="Your email address"
onFocus="if(this.value=='Your email address')this.value='';" onBlur="if(this.value=='')this.value='Your email address';" />
<input type="submit" value="Send" class="submit"/>
</form>
<!-- End Form -->


من هیچ چیزی از فرم ها نمیدونم و الان که چند تا مطلب خوندم و خیلی با هم فرق میکردن کلا گیج شدم php هم بلد نیستم اما اگه یکنفر روی اون کدی که میفرسته یه توضیح بزاره سریع یاد میگیرم

با تشکر

tamafi6
یک شنبه 02 فروردین 1394, 14:21 عصر
ازاین کداستفاده کن



<div class="content">
<h1>Contact Us</h1>
<p>Say hello, using this contact form.</p>
<?php
// Set-up these 3 parameters
// 1. Enter the email address you would like the enquiry sent to
// 2. Enter the subject of the email you will receive, when someone contacts you
// 3. Enter the text that you would like the user to see once they submit the contact form
$to = 'enter email address here';
$subject = 'Enquiry from the website';
$contact_submitted = 'Your message has been sent.';


// Do not amend anything below here, unless you know PHP
function email_is_valid($email) {
return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);
}
if (!email_is_valid($to)) {
echo '<p style="color: red;">You must set-up a valid (to) email address before this contact page will work.</p>';
}
if (isset($_POST['contact_submitted'])) {
$return = "\r";
$youremail = trim(htmlspecialchars($_POST['your_email']));
$yourname = stripslashes(strip_tags($_POST['your_name']));
$yourmessage = stripslashes(strip_tags($_POST['your_message']));
$contact_name = "Name: ".$yourname;
$message_text = "Message: ".$yourmessage;
$user_answer = trim(htmlspecialchars($_POST['user_answer']));
$answer = trim(htmlspecialchars($_POST['answer']));
$message = $contact_name . $return . $message_text;
$headers = "From: ".$youremail;
if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: blue;">'.$contact_submitted.'</p>';
}
else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
}
$number_1 = rand(1, 9);
$number_2 = rand(1, 9);
$answer = substr(md5($number_1+$number_2),5,10);
?>
<form id="contact" action="contact.php" method="post">
<div class="form_settings">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="<?php echo $yourname; ?>" /></p>
<p><span>Email Address</span><input class="contact" type="text" name="your_email" value="<?php echo $youremail; ?>" /></p>
<p><span>Message</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>
<p style="line-height: 1.7em;">To help prevent spam, please enter the answer to this question:</p>
<p><span><?php echo $number_1; ?> + <?php echo $number_2; ?> = ?</span><input type="text" name="user_answer" /><input type="hidden" name="answer" value="<?php echo $answer; ?>" /></p>
<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="contact_submitted" value="send" /></p>
</div>
</form>
</div>

Over Lord 238
یک شنبه 02 فروردین 1394, 18:13 عصر
ازاین کداستفاده کن



<div class="content">
<h1>Contact Us</h1>
<p>Say hello, using this contact form.</p>
<?php
// Set-up these 3 parameters
// 1. Enter the email address you would like the enquiry sent to
// 2. Enter the subject of the email you will receive, when someone contacts you
// 3. Enter the text that you would like the user to see once they submit the contact form
$to = 'enter email address here';
$subject = 'Enquiry from the website';
$contact_submitted = 'Your message has been sent.';


// Do not amend anything below here, unless you know PHP
function email_is_valid($email) {
return preg_match('/^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i',$email);
}
if (!email_is_valid($to)) {
echo '<p style="color: red;">You must set-up a valid (to) email address before this contact page will work.</p>';
}
if (isset($_POST['contact_submitted'])) {
$return = "\r";
$youremail = trim(htmlspecialchars($_POST['your_email']));
$yourname = stripslashes(strip_tags($_POST['your_name']));
$yourmessage = stripslashes(strip_tags($_POST['your_message']));
$contact_name = "Name: ".$yourname;
$message_text = "Message: ".$yourmessage;
$user_answer = trim(htmlspecialchars($_POST['user_answer']));
$answer = trim(htmlspecialchars($_POST['answer']));
$message = $contact_name . $return . $message_text;
$headers = "From: ".$youremail;
if (email_is_valid($youremail) && !eregi("\r",$youremail) && !eregi("\n",$youremail) && $yourname != "" && $yourmessage != "" && substr(md5($user_answer),5,10) === $answer) {
mail($to,$subject,$message,$headers);
$yourname = '';
$youremail = '';
$yourmessage = '';
echo '<p style="color: blue;">'.$contact_submitted.'</p>';
}
else echo '<p style="color: red;">Please enter your name, a valid email address, your message and the answer to the simple maths question before sending your message.</p>';
}
$number_1 = rand(1, 9);
$number_2 = rand(1, 9);
$answer = substr(md5($number_1+$number_2),5,10);
?>
<form id="contact" action="contact.php" method="post">
<div class="form_settings">
<p><span>Name</span><input class="contact" type="text" name="your_name" value="<?php echo $yourname; ?>" /></p>
<p><span>Email Address</span><input class="contact" type="text" name="your_email" value="<?php echo $youremail; ?>" /></p>
<p><span>Message</span><textarea class="contact textarea" rows="5" cols="50" name="your_message"><?php echo $yourmessage; ?></textarea></p>
<p style="line-height: 1.7em;">To help prevent spam, please enter the answer to this question:</p>
<p><span><?php echo $number_1; ?> + <?php echo $number_2; ?> = ?</span><input type="text" name="user_answer" /><input type="hidden" name="answer" value="<?php echo $answer; ?>" /></p>
<p style="padding-top: 15px"><span>&nbsp;</span><input class="submit" type="submit" name="contact_submitted" value="send" /></p>
</div>
</form>
</div>

ببخشید من فقط برای فرمی که نوشم میخوام این فکر کنم برای یک فرم تماس با ما هست. اون فرم Subscribe هست اون بالا میخوام فقط یک آدرس ایمیل رو برام بگیره.

Over Lord 238
یک شنبه 02 فروردین 1394, 18:16 عصر
یک خط جا افتاده بود ممنون فکر کنم کار کرد پیغام رو که داد سایت رو آپلود کردم چک میکنم.

Over Lord 238
سه شنبه 04 فروردین 1394, 18:37 عصر
این کد رو من استفاده کردم ارور نمیده اما به ایمیلی که براش تعریف کردم چیزی نمیفرسته باشپید چکار کنم؟

<?php
if ( isset( $_POST['newsletter_submit'] ) ) {
// Initialize error array
$newsletter_errors = array();

// Check email input field
if ( trim( $_POST['newsletter_email'] ) === '' )
$newsletter_errors[] = 'Email address is required';
elseif ( !preg_match( "/^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,4}$/i", trim( $_POST['newsletter_email'] ) ) )
$newsletter_errors[] = 'Email address is not valid';
else
$newsletter_email = trim( $_POST['newsletter_email'] );

// Send email if no input errors
if ( empty( $newsletter_errors ) ) {
$email_to = "irancsf1@gmail.com"; // Change to your own email address
$subject = "Newsletter Subscription";
$body = "Subscriber details: " . $newsletter_email . "\r\n";
$headers = "Newsletter Subscription <" . $email_to . ">\r\nReply-To: " . $newsletter_email . "\r\n";
mail( $email_to, $subject, $body, $headers );
echo 'Thank you for subscribing!';
} else {
echo 'Please go back and correct the following errors:<br />';
foreach ( $newsletter_errors as $error ) {
echo $error . '<br />';
}
}
}
?>