Despite php already having a mail function called mail(), SMTP sendmail script is preferable. Most importantly, it allows you to bypass the antispam filters, most of which which are set to block the PHP-mail by default.

With an SMTP script, you can completely disguise the letter and make everyone think that it was not sent from with a mail() function.

How to write a sendmail SMTP script

Creating a function to work with an open SMTP-connection

<?
function get_data($smtp_conn)
{
$data="";
while($str = fgets($smtp_conn,515))
{
$data .= $str;
if(substr($str,3,1) == " ") { break; }
}
return $data;
}
?>

Creating the letter

<?
$header.="X-Mailer: The Bat! (v3.99.3) Professional\r\n"; 
$header.="Reply-To: =?utf-8?Q?".str_replace("+","_",str_replace("%","=",urlencode('sender')))."?= <sender@domain.com>\r\n";

Change utf-8  to the encoding system you are using, sender – to the sender name, and sender@domain.com – to the email you are going to send the letter from.

$header.="X-Priority: 3 (Normal)\r\n";
$header.="Message-ID: <172562218.".date("YmjHis")."@domain.com>\r\n";

Change @domain.com to the domain where your mail is located.

$header.="To: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode('recipient')))."?= <recipient@domain.ru>\r\n";

Change utf-8 to the encoding system that you are using, recipient to the name of the letter’s recipient, and  recipient@domain.com — to their domain

$header.="Subject: =?windows-1251?Q?".str_replace("+","_",str_replace("%","=",urlencode('check')))."?=\r\n";
 $header.="MIME-Version: 1.0\r\n";
 $header.="Content-Type: text/plain; charset=windows-1251\r\n";
 $header.="Content-Transfer-Encoding: 8bit\r\n";
 ?>

Change check to the letter’s subject.

$text="Hi, how do you do?";

Change  Hi, how do you do? to your letter’s text.

Sending the letter

<?
$smtp_conn = fsockopen("smtp.mail.ru", 25,$errno, $errstr, 10);
$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,"EHLO johnny\r\n");

If you want to, you can change johnny to anything else. But it is only an ID the server will assign to your PC, so it’s not important.

$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,"AUTH LOGIN\r\n");
$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,base64_encode("login")."\r\n");

Change login to your login on the mail server.

$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,base64_encode("password")."\r\n");

Change password to your password on the mail server.

$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
$size_msg=strlen($header."\r\n".$text);
fputs($smtp_conn,"MAIL FROM:<sender@domain.com> SIZE=".$size_msg."\r\n");

Change sender@domain.com to the mailing address that will be used to send the letter.

$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,"RCPT TO:<recipient@domain.com>\r\n");

Change recipient@domain.com to the recipient’s mailing address.

$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,"DATA\r\n");
$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,$header."\r\n".$text."\r\n.\r\n");
$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
fputs($smtp_conn,"QUIT\r\n");
$data = get_data($smtp_conn);
//$code = substr($data,0,3);
//echo ($code);
?>

This script can be used to send mail from any hosting or a server that supports PHP.