TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 03-11-2010, 01:21 PM   #1 (permalink)
The Wanderer
 
Hashimi's Avatar
 
Join Date: Sep 2007
Posts: 10
Thanks: 2
Hashimi is on a distinguished road
Default Execute two job when post

Hi everyone;

I want to code a part of my project, i aim to give it this functionality: When i execute informations in <input .. > ( I mean when He/She press the "Submit" button) at the same time, i want to execute the function sendmail() too. How i do this.

Thanks
Hashimi is offline  
Reply With Quote
Old 03-11-2010, 03:52 PM   #2 (permalink)
The Contributor
 
Tim Dobson's Avatar
 
Join Date: Feb 2010
Posts: 69
Thanks: 16
Tim Dobson is on a distinguished road
Default

well i have a similar script to what you are probably asking of... when a user uploads a file to the server i have it send me an e mail to tell me there has been a file put on the system.

just drop an e mail script at the bottom..

PHP Code:
//lets send the e mail with the data...
$to "tim@tentun.co.uk";
$subject "New template!";
$filename str_replace(" ""%20"$filename);
$body 'New template has been uploaded by ' $thename ' E-Mail - ' $themail ' Template name - ' $thetemplatename ' URL - ' $urlloc $filename '';
$headers "From: tim@tentun.co.uk\r\n" .
    
"X-Mailer: php";
if (
mail($to$subject$body$headers)) {
  echo(
"<p>A notification has been sent to the site and your template will be added ASAP!</p>");
 } else {
  echo(
"<p>Message delivery failed...</p>");
 } 

Thats just an example of my e mail message that should be sent.. my full layout is

PHP Code:
<?php
   
// Configuration - Your Options
      
$allowed_filetypes = array('.zip','.txt'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path '../uploads/'// The place the files will be uploaded to (currently a 'files' directory).
 
   
$filename $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'The file you attempted to upload is not allowed.');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die(
'The file you attempted to upload is too large.');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'You cannot upload to the specified directory, please CHMOD it to 777.');
 
   
// We'll start handling the upload in the next step
 
?>

<?php
   
// Configuration - Your Options
      
$allowed_filetypes = array('.zip','.txt'); // These will be the types of file that will pass the validation.
      
$max_filesize 2097152// Maximum filesize in BYTES (currently 2MB).
      
$upload_path '../uploads/'// The place the files will be uploaded to (currently a 'files' directory).
      
$urlloc 'http://www.tentun.co.uk/sb0t/uploads/';
      
$themail $_REQUEST["email"];
      
$thename $_REQUEST["yourname"];
      
$thetemplatename $_REQUEST["templatename"];
   
$filename $_FILES['userfile']['name']; // Get the name of the file (including file extension).
   
$ext substr($filenamestrpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
 
   // Check if the filetype is allowed, if not DIE and inform the user.
   
if(!in_array($ext,$allowed_filetypes))
      die(
'The file you attempted to upload is not allowed.');
 
   
// Now check the filesize, if it is too large then DIE and inform the user.
   
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
      die(
'The file you attempted to upload is too large.');
 
   
// Check if we can upload to the specified path, if not DIE and inform the user.
   
if(!is_writable($upload_path))
      die(
'You cannot upload to the specified directory, please CHMOD it to 777.');
 
   
// Upload the file to your specified path.
   
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path $filename))
         echo 
'Your file upload was successful'// It worked.
      
else
         echo 
'There was an error during the file upload.  Please try again.'// It failed :(.
                                                                                              
//lets send the e mail with the data...
$to "tim@tentun.co.uk";
$subject "New template!";
$filename str_replace(" ""%20"$filename);
$body 'New template has been uploaded by ' $thename ' E-Mail - ' $themail ' Template name - ' $thetemplatename ' URL - ' $urlloc $filename '';
$headers "From: tim@tentun.co.uk\r\n" .
    
"X-Mailer: php";
if (
mail($to$subject$body$headers)) {
  echo(
"<p>A notification has been sent to the site and your template will be added ASAP!</p>");
 } else {
  echo(
"<p>Message delivery failed...</p>");
 }                                                          
 
?>

<?php

//  refresh / redirect to an internal web page
//  ------------------------------------------
header'refresh: 5; url=../index.php' );
echo 
'<h1>You will be re-directed in 5 seconds...</h1>';
?>
Tim Dobson is offline  
Reply With Quote
The Following User Says Thank You to Tim Dobson For This Useful Post:
Hashimi (03-23-2010)
Old 03-12-2010, 05:51 PM   #3 (permalink)
The Wanderer
 
Hashimi's Avatar
 
Join Date: Sep 2007
Posts: 10
Thanks: 2
Hashimi is on a distinguished road
Default

Thanks for Links. It will help me with i aim to do. I will share my codes after i did it. And yeah also if i can't i will be back here :)
Hashimi is offline  
Reply With Quote
Old 03-23-2010, 01:31 PM   #4 (permalink)
The Wanderer
 
Hashimi's Avatar
 
Join Date: Sep 2007
Posts: 10
Thanks: 2
Hashimi is on a distinguished road
Default

Hi;
Because my new question was related to this topic i asked here;

I want to mail members at a specific time of the day or night. How can i check.

Thanks
Hashimi is offline  
Reply With Quote
Old 03-23-2010, 04:55 PM   #5 (permalink)
is cute and cuddly
 
delayedinsanity's Avatar
 
Join Date: Mar 2008
Location: Vegas, Baby
Posts: 963
Thanks: 31
delayedinsanity is on a distinguished road
Default

Your best bet is to look into creating a cron job. You can run a script on your web site that will emulate this by checking the time and performing the specified task if it is or is past a specific time, however you're then adding the overhead to each and every visitor of your web site.
delayedinsanity is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
My post shows up as NEW allworknoplay Feedback 5 05-06-2009 01:35 PM
Venerable methods and the applications they are commonly trusted in. Village Idiot Tips & Tricks 7 11-06-2008 07:36 AM
fetch data in a form without using post? kororo203 Absolute Beginners 5 05-14-2008 01:37 AM
POST Metod in Zend Framework krum Absolute Beginners 5 03-11-2008 03:17 PM


All times are GMT. The time now is 04:43 AM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design