Share4Mates blog

Fast, easy & FREE Services!

PHP mail form UTF-8 Encoding

June14

$to = "BGEstates";
$subject = "BGEstates - Заказать обратный звонк";
$name_field = $_POST['name'];
$phone_field = $_POST['phone'];
$email_field = $_POST['email'];
$message = $_POST['message'];
$headers .= "Content-Type: text/html; " . "charset=UTF-8; format=flowed\n" . "MIME-Version: 1.0\n" . "Content-Transfer-Encoding: 8bit\n" . "X-Mailer: PHP\n";
$headers .= "From: " . "=?UTF-8?B?" . base64_encode($name_field) . "?=" . "<" . $email_field . ">";

$body = " From: $name_field\n E-Mail: $email_field\n Phone: $phone_field\n \n Message:\n $message";

$mail = mail($to, $subject, $body, $headers);

if($mail){
echo 'OK';
}

}
else{
echo '

‘.$error.’

‘;
}

}

?>

posted under PHP |

Speed limited File download

October1
// local file that should be send to the client
$local_file = 'test-file.zip';
// filename that the user gets as default
$download_file = 'your-download-name.zip';

// set the download rate limit (=> 20,5 kb/s)
$download_rate = 20.5;
if(file_exists($local_file) && is_file($local_file)) {
    // send headers
    header('Cache-control: private');
    header('Content-Type: application/octet-stream');
    header('Content-Length: '.filesize($local_file));
    header('Content-Disposition: filename='.$download_file);

    // flush content
    flush();
    // open file stream
    $file = fopen($local_file, "r");
    while(!feof($file)) {

        // send the current file part to the browser
        print fread($file, round($download_rate * 1024));    

        // flush the content to the browser
        flush();

        // sleep one second
        sleep(1);
    }    

    // close file stream
    fclose($file);}
else {
    die('Error: The file '.$local_file.' does not exist!');
}
posted under PHP |

PHP mail sending on Windows mail server.

April15

For all of the people struggling with getting PHP mail() sending to some, but not all, recipients…look no farther. Your solution has been posted here.

It appears PHP-generated emails don’t play nice on Windows mail servers. So, when your mail goes to anyone who uses a Windows mail server (Comcast, gmail, and maybe aol), the recipients won’t get it. UNLESS YOU ADD THE LINE:

<?php

phpini_set(“sendmail_from”, “info@mydomain.com”);

?>

posted under PHP |