Skip to main content

Specify a return-path for generated mail

Specify a return-path for generated mail
You may want to specify a return-path for your website generated mail.  This is the address to which rejected mail will be returned.  This is very different from a return address.  You can specify the return-path by using the -f parameter in the mail() function or specifying the -f parameter as a default in a php.ini file.

You can put the -f parameter in the mail() function, as follows :
mail($toEmailAddress,$subject,$message,$headers,"-f$returnPathAddress");
Is is a fifth parameter, and note there is no space between the -f and the email address.

You can specify a default return-path in your php.ini file using this line:
sendmail_path = /usr/sbin/sendmail -t -i -femail@domain.com
Ensure the sendmail path is correct for your host, and again note there is no space between the -f and the email address.

Clean up your PHP scripts
Scripting in php can get very messy.  Typically you build your html as you go, so you have your php logic and your html all mixed up.  IMHO, a better way is to separate your html from your php logic. Then you can edit your html page in a standard html editor, and work on your logic independently.  This will make your site much easier to maintain.  You can build very complex sites in this way, while keeping your scripts easy to understand.  Build the variable content of your page in php, put the variable names in your html, and then as the last php line use this:

- - Start Script Here - -
<?phpeval("echo(\"".str_replace("\"","\\\"",file_get_contents("page.htm"))."\");");?>
- - End Script Here - -

This assumes that the html page is named page.htm.  This line of code will take page.htm and replace all the $variable name with the corresponding value from the php script, and output the page.  For more complex pages you can put html in the variables and you can add to a variable's value in the php script while you are building the page, for creating lists.  This method was used to build this page and the page for www.prettyworthless.com.

If you just want to evaluate the html in the external file (meaning load variable values) and save the result in a variable for later echo or other use then consider this variation

- - Start Script Here - -
<?phpeval("\$variable = \"".str_replace("\"","\\\"",file_get_contents("page.htm"))."\";");?>
- - End Script Here - -

Delete session files
Assuming you are using a custom php.ini file and have specified a user directory where session records are stored, this script can be used to delete old session files (the system will not purge them, so the directory will keep growing if you do not delete them).   You must change the $sessionDir variable to the path where your session files are stored, and you can adjust the delete time frame as well (the example below uses 3 hours - you would not want to delete an active session).   You can run this script directly or set it up to run at specific time intervals using cron.

- - Start Script Here - -
<?php
$sessionDir 
"/home/user/temp";  // your sessions directory$compareTime time() - 10800;  // 3 hours$dir opendir("$sessionDir");
while ((
$file readdir($dir)) !== false) {
  if (
substr($file,0,4) == "sess") {
    if (
$compareTime >= filemtime("$sessionDir/$file")) {
      if (
unlink ("$sessionDir/$file")) $count++;
    }
  }
}  
closedir($dir);
echo 
"$count session files were deleted";?>

- - End Script Here - -


Deleteing php.ini files
 You can find another Tip on this page for how to create a custom php.ini file.  And another for how to populate directories with your php.ini file in the event your host requires you to have one in each directory with php scripts.  But then if you want to delete all the php.ini files, you may need this script.  It will delete any php.ini file from your main public directory and all subdirectories.

- - Start Script Here - -
<?php// this script will delete all your php.ini files$path "/home/" get_current_user() . "/public_html";
function 
search($dir) {
  
$dh opendir($dir);
  while ((
$filename readdir($dh)) !== false) {
    if ( 
$filename !== '.' AND $filename !== '..' AND $filename !== 'cgi-bin' AND is_dir("$dir/$filename") ) {
      
$path $dir."/".$filename;
      
$target $path "/php.ini";
      if (
file_exists($target)) {
        echo 
"Deleting - $target <br>";
        if (!
unlink($target)) echo "<b>Delete failed for $target </b><br>";
    }
      
search($path);
    }
  }
  
closedir($dh);
}
$target $path "/php.ini";
if (
file_exists($target)) {
  echo 
"Deleting - $target <br>";
  if (!
unlink($target)) echo "<b>Delete failed for $target </b><br>";
}
search($path);
echo 
"<br>Done.";?> 

- - End Script Here - -

Comments

Popular posts from this blog

links

0.  https://michael67654.qowap.com/64523001/new-pos-technique-to-perk-up-your-company 1.  https://johnnydinqr.blog2learn.com/52856602/new-pos-system-to-perk-up-your-company 2.  http://edwinsqgcu.onesmablog.com/New-POS-Process-to-Perk-Up-Your-company-43309737 3.  http://chloe69246.bloguetechno.com/New-POS-Process-to-Perk-Up-Your-Business-39814721 4.  http://jacob87541.pointblog.net/New-POS-Technique-to-Perk-Up-Your-online-business-43741223 5.  http://arlette53302.thezenweb.com/New-POS-System-to-Perk-Up-Your-online-business-41464611 6.  http://devinpixna.tinyblogging.com/New-POS-Program-to-Perk-Up-Your-online-business-46354577 7.  https://rylanevsom.blog5.net/46759651/new-pos-program-to-perk-up-your-small-business 8.  https://mariowoesh.affiliatblogger.com/56515206/new-pos-system-to-perk-up-your-organization 9.  https://liam66429.diowebhost.com/60164326/new-pos-procedure-to-perk-up-your-company 10.  https://henry19219.fitnell.com/4557...

Raisonnement, la résolution de problèmes

Les chercheurs ont d'abord développé des algorithmes mimétiques raisonnement humain étapes que les gens utilisent pour résoudre le casse-tête ou faire méthode d'exclusion logique. [2] Dans les années 1980 et 1990 fin, l'étude de la grippe aviaire a développé des méthodes de traitement de l'information incertaine ou incomplète, en utilisant des concepts de probabilité et de l'économie. [3] Pour ces problèmes, les algorithmes requis matériel assez puissant pour effectuer des calculs de géant - à subir « combinaisons d'explosion »: la quantité de mémoire et le temps de calcul peut devenir invisible prendre si la résolution d'un problème difficile. La plus haute priorité est l'algorithme de recherche pour résoudre le problème.  Les gens utilisent généralement les jugements rapides et intuitifs plutôt que pas de déduction que les chercheurs en IA d'origine peuvent simuler. [5] Amnesty International a progressé en utilisant la résolution de problèmes « c...

Tracking and Securing Downloads

If you want to report or track downloads from your website, try this script.   This script will send you an email every time you have a download.   The email will tell you what file was downloaded and who did the download.   You could change this script to keep counts (store them in flat file or MySQL) if you desire. The variable $directory is the directory where the download files are located.   If you want the script in the same directory as the files then use "./" as the directory (you must always have the slash). In your html page, use the following structure as your download link (where name.txt is the file name to download): <a href="download.php?file=name.txt">download</a> Then you use the following script (called download.php): - - Start Script Here - - <?php $emailaddress  =  "email@yourdomain.com" ; $filename  =  $_GET [ 'file' ]; $directory  =  "downloads/" ; $path  =  "$directory$filename" ; putenv (...