Jos ajat lokaalilta koneelta, niin mitä todennäköisimmin meilisi menee spammiroskiin toisessa päässä.
Aja mail() siis hostipalvelimella, niin saat meilit perille saakka.
Tässä kuitenkin standardin mukainen koodi:
if (!defined('PHP_EOL')) {
if (strtoupper(substr(PHP_OS, 0, 3) == 'WIN'))
define('PHP_EOL', "\r\n");
elseif (strtoupper(substr(PHP_OS, 0, 3) == 'MAC'))
define('PHP_EOL', "\r");
else // Unix
define('PHP_EOL', "\n");
}
/**
Send email
Note: Requires sendmail on server! See more detailes from PHP manual mail() function..
If sendmail is returning true, it does not necessarily mean the email was correctly sent to the recipient!
@param to - receiver address
@param from - sender address
@param subjct - subject of the message
@param msg - message body
@param ctype - content type (typically text/plain or text/html)
@param charset - character set (typically utf-8 or iso-8859-1)
@return - true if (assumed) success, false if error
*/
function send_email($to, $from, $subject, $msg, $ctype = 'text/plain', $charset = 'utf-8') {
$header = "MIME-Version: 1.0" . PHP_EOL;
$header .= "Content-type: $ctype; charset=$charset" . PHP_EOL; // If other than text/plain, please modify!
$header .= "From: $from" . PHP_EOL;
$header .= "Reply-To: $from" . PHP_EOL;
$header .= "Return-Path: $from" . PHP_EOL;
$header .= "Date: " . date("r") . PHP_EOL;
$header .= "Message-ID: <" . microtime() . " TheSystem@". $_SERVER['SERVER_NAME'].">" . PHP_EOL;
$header .= "X-Mailer: PHP v" . phpversion() . PHP_EOL;
$msg .= PHP_EOL;
$msg = wordwrap($msg, 70);
return mail($to, $subject, $msg, $header);
}