Skip to content

Instantly share code, notes, and snippets.

@ozzi-
Last active December 14, 2018 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ozzi-/62137f4b0358c2c1609b3dfdf1cb070d to your computer and use it in GitHub Desktop.
Save ozzi-/62137f4b0358c2c1609b3dfdf1cb070d to your computer and use it in GitHub Desktop.
<?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