Source:Email verschicken
Aus Alexander's Wiki
Version vom 13. August 2010, 08:53 Uhr von 134.169.164.188 (Diskussion) (Die Seite wurde neu angelegt: „Diese Seite muss noch weiter überarbeitet werden ---- == Email per PHP == Dieses Script verschickt nicht nur eine Email, sondern macht vorher ein Backup von ei…“)
Diese Seite muss noch weiter überarbeitet werden
Email per PHP
Dieses Script verschickt nicht nur eine Email, sondern macht vorher ein Backup von einer mySQL-Datenbank und verschickt dieses als Email. Ich denke, man kann beide Funktionen auseinander halten.
<?php
/* Database */
$db = "database";
$dbuser = "username";
$dbpw = "password";
$dbhost = "localhost";
/* Email*/
$to = "emailadresse";
/* Misc */
$file = "_B_A_C_K_U_P_" . $db . ".sql.gz";
$message = "Backup ".$file." of ".$dbhost." attached.\n\n-- \n" . strip_tags($_SERVER["SERVER_SIGNATURE"]);
$subject = "Backup ".$file;
$from = "MySQL-Backup<".$_SERVER["SERVER_ADMIN"].">";
/* Systemcall */
system("/usr/bin/mysqldump -u".$dbuser." -p".$dbpw." -h ".$dbhost." ".$db." | /bin/gzip > ".$file, $fp);
if ($fp==0) echo "Dump generated"; else die("Ooops. An error occured!");
/* Prepare the email*/
$boundary = strtoupper(md5(uniqid(time())));
$mail_header = "From:".$from."\n";
$mail_header .= "MIME-Version: 1.0";
$mail_header .= "\nContent-Type: multipart/mixed; boundary=".$boundary;
$mail_header .= "\n\nThis is a multi-part message in MIME format -- Dies ist eine mehrteilige Nachricht im MIME-Format";
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: text/plain";
$mail_header .= "\nContent-Transfer-Encoding: 8bit";
$mail_header .= "\n\n".$message;
$file_content = fread(fopen($file,"r"),filesize($file));
$file_content = chunk_split(base64_encode($file_content));
$mail_header .= "\n--".$boundary;
$mail_header .= "\nContent-Type: application/octetstream; name=\"".$file."\"";
$mail_header .= "\nContent-Transfer-Encoding: base64";
$mail_header .= "\nContent-Disposition: attachment; filename=\"".$file."\"";
$mail_header .= "\n\n".$file_content;
$mail_header .= "\n--".$boundary."--";
/* Send the email */
mail($to,$subject,"",$mail_header);
?>