PHP E-Mails mit Anhängen versenden

<?php

define('SERVER_NAME', preg_replace('/www./i', '', $_SERVER['SERVER_NAME']));

define('DATATYPE', 1); // 0 = text/plain | 1 = text/html

$type = 'normal';

switch ($type) {

    case 'high':
        $priority = 1;
        $importance = 'High';
        break;

    case 'normal':
        $priority = 3;
        $importance = 'Normal';
        break;

    default:
        $priority = 3;
        $importance = 'Normal';
        break;
}

$attachment = array();

$attachment[] = array(
    'type' => 'text/plain',
    'name' => 'index.htm',
    'data' => file_get_contents(getcwd().'/index.htm')
);

$from = SERVER_NAME.' <demo@'.SERVER_NAME.'>';

$subject = 'Demo - '.SERVER_NAME;

$cc = null;

$bcc = null;

$header = "From: ".$from.PHP_EOL;

if (!is_null($cc)) { $header .= "Cc: ".$cc.PHP_EOL; }

if (!is_null($bcc)) { $header .= "Bcc: ".$bcc.PHP_EOL; }

$header .= "Message-Id: <".sha1(microtime())."@".SERVER_NAME.">".PHP_EOL;
$header .= "X-Mailer: PHP ".phpversion().PHP_EOL;
$header .= "MIME-Version: 1.0".PHP_EOL;
$header .= "X-Priority: ".$priority.PHP_EOL;
$header .= "Importance: ".$importance.PHP_EOL;

$boundary = '-----='.hash('md5', uniqid(mt_rand(), 1));

$content = (string) '';

$header .= 'Content-Type: multipart/mixed;'.PHP_EOL;
$header .= ' boundary="'.$boundary.'"'.PHP_EOL;

$content .= 'This is a multi-part message in MIME format'.PHP_EOL.PHP_EOL;
$content .= '--'.$boundary.PHP_EOL;

$type = (DATATYPE === 0) ? 'text/html' : 'text/plain';

if (count($attachment) > 0) {

    $content .= 'Content-Type: '.$type.'; charset=utf-8'.PHP_EOL;
    $content .= 'Content-Transfer-Encoding: 8bit'.PHP_EOL.PHP_EOL;
}
else {

    $header .= 'Content-Type: '.$type.'; charset=utf-8'.PHP_EOL;
    $header .= 'Content-Transfer-Encoding: 8bit';
}

$content .= 'Inhalt der E-Mail'.PHP_EOL;

if (count($attachment) > 0) {

    foreach ($attachment as $data) {

        $content .= PHP_EOL.'--'.$boundary.PHP_EOL;
        $content .= 'Content-Type: '.$data['type'].'; name='.$data['name'].PHP_EOL;
        $content .= 'Content-Transfer-Encoding: base64'.PHP_EOL;
        $content .= 'Content-Disposition: attachment; filename='.$data['name'].PHP_EOL.PHP_EOL;
        $content .= chunk_split(base64_encode($data['data']));
    }

    $content .= "\n".'--'.$boundary.'--';
}

var_dump(mail('empfaenger@domain.de', $subject, $content, $header)); // liefert TRUE oder FALSE

IBAN validieren

<?php

function validate_IBAN( $iban ) {
    
    $iban = str_replace( ' ', '', $iban );
    
    $clean = substr( $iban, 4 )
        . strval( ord( $iban{0} ) - 55 )
        . strval( ord( $iban{1} ) - 55 )
        . substr( $iban, 2, 2 );

    $rest = 0;
    
    for ( $pos = 0; $pos < strlen( $clean ); $pos += 7 ) {
        
        $part = strval( $rest ) . substr( $clean, $pos ,7 );
        $rest = intval( $part ) % 97;
    }
    
    // Prüfziffer
    $spf = sprintf("%02d", 98 - $rest);

    if ( substr( $iban, 2, 2 ) == '00' )
        return substr_replace( $iban, $spf, 2, 2 );
    else
        return ($rest == 1) ? true : false;
}

var_dump(validate_IBAN('YOUR_IBAN'));