Last active
December 14, 2018 08:38
-
-
Save ozzi-/62137f4b0358c2c1609b3dfdf1cb070d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function smtpSend($to, $from, $message, $host, $port, &$error){ | |
$recipientString=""; | |
if ($h = fsockopen($host, $port, $errno, $errstr, 5)){ | |
$data = array(); | |
array_push($data, 0); | |
array_push($data, "EHLO $host"); | |
array_push($data, "MAIL FROM: <$from>"); | |
if(is_array($to)){ | |
foreach ($to as $toRcpt) { | |
array_push($data, "RCPT TO: <$toRcpt>"); | |
$recipientString = $recipientString.$toRcpt.","; | |
} | |
}else{ | |
array_push($data, "RCPT TO: <$to>"); | |
$recipientString = $to; | |
} | |
array_push($data, "DATA"); | |
array_push($data, $message."\r\n."); | |
foreach($data as $c){ | |
$c && fwrite($h, "$c\r\n"); | |
do{ | |
$r = fgets($h, 256); | |
if(substr($r,0,1)==="5"){ | |
$error = "SMTP ERROR: ".$r; | |
return false; | |
} | |
}while(substr($r,3,1)==="-"); | |
} | |
fwrite($h, "QUIT\r\n"); | |
$r = strtolower($r); | |
if(substr($r,0,6)!=="250 ok"){ | |
$error = "SMTP ERROR: Last response was not 250 OK but: ".$r; | |
return false; | |
}else{ | |
return true; | |
} | |
return fclose($h); | |
} | |
$error = "Could not send mail, fsockopen failed"; | |
return false; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment