Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Simple contact form
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Weasel" data-source="post: 167996" data-attributes="member: 9520"><p>I have been working on a little contact script to intergrate with SmashCMS, however I don't have any time to do it. So here is a little, simple, contact script. Currently there is no anti-spam check, however if people would like to see this, I'll add it.</p><p> </p><p>The core PHP file:</p><p>[PHP]<?php</p><p>session_start();</p><p> $hour = date("H");</p><p> $minute = date("i");</p><p> $seconds = date("s");</p><p> $day = date("d");</p><p> $month = date("m");</p><p> $year = date("Y");</p><p>$extratime = 30;</p><p> </p><p>$current = mktime($hour,$minute,$seconds,$month,$day,$year);</p><p>$expire = mktime($hour,$minute,$seconds+$extratime,$month,$day,$year);</p><p> </p><p> $firstname = $_POST['firstname'];</p><p> $surname = $_POST['surname'];</p><p> $email = $_POST['email'];</p><p> $message = $_POST['message'];</p><p> </p><p> $to = 'YOUR@EMAIL.com';</p><p> $subject = 'Message from '.$firstname.' '.$surname.' with IP '.$_SERVER['REMOTE_ADDR'].'';</p><p> </p><p> $headers = "MIME-version: 1.0\r\n";</p><p> $headers .= "content-type: text/html;charset=utf-8\r\n";</p><p> </p><p>if(isset($_POST['send']))</p><p>{</p><p>$check_status = '';</p><p>$errors = array();</p><p> </p><p>if (isset($_SESSION['check']) && $_SESSION['check'] > $current)</p><p>{</p><p>$errors[] = 'Please wait '.$extratime.' seconds before sending another message..';</p><p>}</p><p>if(empty($firstname))</p><p>{</p><p>$errors[] = 'The field "First name" is empty!';</p><p>}</p><p>if(empty($surname))</p><p>{</p><p>$errors[] = 'The field "Surname" is empty!';</p><p>}</p><p>if(empty($email))</p><p>{</p><p>$errors[] = 'The field "E-mail address" is empty!';</p><p>}</p><p>if(!filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($email))</p><p>{</p><p>$errors[] = 'The given e-mail address is invalid. Please fill in a good one.';</p><p>}</p><p>if(empty($message))</p><p>{</p><p>$errors[] = 'The field "Message" is empty!';</p><p>}</p><p> </p><p>if(count($errors) == 0)</p><p>{</p><p>$headers .= 'From: ' . $firstname . ' ' . $surname . '<' . $email . '>';</p><p> </p><p>if(mail($to, $subject, nl2br($message), $headers))</p><p>{</p><p>$check_status = 'Your message has been succesfully send!!';</p><p>$_SESSION['check'] = $expire;</p><p>}</p><p>else</p><p>{</p><p>$errors[] = 'A system error occured.';</p><p>}</p><p>}</p><p>}</p><p> </p><p>foreach($errors as $key => $keyvalue){</p><p>$check_status .= ''.$keyvalue.'<br>';</p><p>}</p><p>?>[/PHP]</p><p> </p><p>The form:</p><p>[code] <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"></p><p>First name<br /></p><p><input type="text" name="firstname" /><br /><br /></p><p>Surname<br /></p><p><input type="text" name="surname" /><br /><br /></p><p>E-mail address<br /></p><p><input type="text" name="email" /><br /><br /></p><p>Your message<br /></p><p><textarea cols="50" rows="12" name="message"></textarea><br /><br /></p><p><input type="reset" value="Empty fields" /> <input type="submit" name="send" value="Send message" /></p><p></form>[/code]</p><p> </p><p>The PHP code to let the error/succes messages show. Place this piece of code on the spot you want this to show:</p><p>[PHP]<?php</p><p>if ($check_status != ''){</p><p>echo $check_status;</p><p>}</p><p>?>[/PHP]</p><p> </p><p>Do not forget to set the $extratime variable to the amount of seconds you want people to wait before sending another email, and also change the $to variable with your own email.</p><p> </p><p>If you have any errors, please say so. I'll try to fix it. Ideas are welcome to.</p></blockquote><p></p>
[QUOTE="Weasel, post: 167996, member: 9520"] I have been working on a little contact script to intergrate with SmashCMS, however I don't have any time to do it. So here is a little, simple, contact script. Currently there is no anti-spam check, however if people would like to see this, I'll add it. The core PHP file: [PHP]<?php session_start(); $hour = date("H"); $minute = date("i"); $seconds = date("s"); $day = date("d"); $month = date("m"); $year = date("Y"); $extratime = 30; $current = mktime($hour,$minute,$seconds,$month,$day,$year); $expire = mktime($hour,$minute,$seconds+$extratime,$month,$day,$year); $firstname = $_POST['firstname']; $surname = $_POST['surname']; $email = $_POST['email']; $message = $_POST['message']; $to = 'YOUR@EMAIL.com'; $subject = 'Message from '.$firstname.' '.$surname.' with IP '.$_SERVER['REMOTE_ADDR'].''; $headers = "MIME-version: 1.0\r\n"; $headers .= "content-type: text/html;charset=utf-8\r\n"; if(isset($_POST['send'])) { $check_status = ''; $errors = array(); if (isset($_SESSION['check']) && $_SESSION['check'] > $current) { $errors[] = 'Please wait '.$extratime.' seconds before sending another message..'; } if(empty($firstname)) { $errors[] = 'The field "First name" is empty!'; } if(empty($surname)) { $errors[] = 'The field "Surname" is empty!'; } if(empty($email)) { $errors[] = 'The field "E-mail address" is empty!'; } if(!filter_var($email, FILTER_VALIDATE_EMAIL) && !empty($email)) { $errors[] = 'The given e-mail address is invalid. Please fill in a good one.'; } if(empty($message)) { $errors[] = 'The field "Message" is empty!'; } if(count($errors) == 0) { $headers .= 'From: ' . $firstname . ' ' . $surname . '<' . $email . '>'; if(mail($to, $subject, nl2br($message), $headers)) { $check_status = 'Your message has been succesfully send!!'; $_SESSION['check'] = $expire; } else { $errors[] = 'A system error occured.'; } } } foreach($errors as $key => $keyvalue){ $check_status .= ''.$keyvalue.'<br>'; } ?>[/PHP] The form: [code] <form method="POST" action="<?php echo $_SERVER['PHP_SELF']; ?>"> First name<br /> <input type="text" name="firstname" /><br /><br /> Surname<br /> <input type="text" name="surname" /><br /><br /> E-mail address<br /> <input type="text" name="email" /><br /><br /> Your message<br /> <textarea cols="50" rows="12" name="message"></textarea><br /><br /> <input type="reset" value="Empty fields" /> <input type="submit" name="send" value="Send message" /> </form>[/code] The PHP code to let the error/succes messages show. Place this piece of code on the spot you want this to show: [PHP]<?php if ($check_status != ''){ echo $check_status; } ?>[/PHP] Do not forget to set the $extratime variable to the amount of seconds you want people to wait before sending another email, and also change the $to variable with your own email. If you have any errors, please say so. I'll try to fix it. Ideas are welcome to. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Simple contact form
Top