TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   General (http://www.talkphp.com/general/)
-   -   Execute two job when post (http://www.talkphp.com/general/5343-execute-two-job-when-post.html)

Hashimi 03-11-2010 01:21 PM

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

Tim Dobson 03-11-2010 03:52 PM

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>';
?>


Hashimi 03-12-2010 05:51 PM

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 03-23-2010 01:31 PM

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

delayedinsanity 03-23-2010 04:55 PM

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.


All times are GMT. The time now is 11:24 AM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0