function send() { // Iterate through each recipient for ($i = 0; $i < count($this->recipients); $i++) { // Get domain from recipient address $address = explode('@', $this->recipients[$i]['email'], 2); $domain = @$address[1]; // Get MX address $mxQuery = new mxQuery($this->dnsServer); $mxAddress = $mxQuery->getmxr($domain); // Generate headers $headers = null; for ($n = 0; $n < count($this->headers); $n++) { // Get from address from header if ($this->headers[$n]['name'] == 'From') { $fromAddress = $this->headers[$n]['value']; if (strpos($fromAddress, '<') !== false) { $fromAddress = substr($fromAddress, strpos($fromAddress, '<') + 1, strpos($fromAddress, '>') - (strpos($fromAddress, '<') + 1)); } } if ($this->headers[$n]['name'] == 'To') { // If no specifed To header, automatically generate if (!$headers[$n]['value']) { $headers .= $this->headers[$n]['name'] . ': ' . $this->generateTo() . "\r\n"; } } else { // Add headers to headers string $headers .= $this->headers[$n]['name'] . ': ' . $this->headers[$n]['value'] . "\r\n"; } } // Terminate headers to prevent injection from body $headers .= "\r\n"; // Set from address to announceEmail if specified if ($this->announceEmail) { $fromAddress = $this->announceEmail; } // Generate main message $message = $this->message; // Set status messages $this->status[$i]['name'] = $this->recipients[$i]['name']; $this->status[$i]['address'] = $this->recipients[$i]['email']; $this->status[$i]['domain'] = $domain; $this->status[$i]['mxAddress'] = $mxAddress; $this->status[$i]['fromAddress'] = $fromAddress; $this->status[$i]['headers'] = $headers; $this->status[$i]['message'] = $message; // Done seperately to avoid bug in PHP < 4.3.0 $this->status[$i]['message'] = str_rot13($this->status[$i]['message']); // Open connection to reciving server $mxServer = @fsockopen($mxAddress, 25, $null1, $null2, 5); if ($mxServer) { // Update status, connection success $this->status[$i]['connected'] = true; // Prevent a blocked socket holding up script socket_set_timeout($mxServer, 5); // Add status array for server response $this->status[$i]['mxResponse'] = array(); // Handshake with MX server. Store all responses in status array array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "HELO " . $this->greeting . "\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "MAIL FROM:<" . $fromAddress . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); // Inform MX server of destination email address fwrite($mxServer, "RCPT TO:<" . $this->recipients[$i]['email'] . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); // Send message data fwrite($mxServer, "DATA\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, $headers); // Note: header termination is fwrite($mxServer, $message); // done during header creation. fwrite($mxServer, "\r\n.\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); // Close connection fwrite($mxServer, "QUIT\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fclose($mxServer); } else { // Update status,connetion failure $this->status[$i]['connected'] = false; } } // Return status $status = true; for ($n = 0; $n < count($this->status); $n++) { if (!$this->status[$n]['connected']) { $status = false; } } return $status; }
function send() { for ($i = 0; $i < count($this->recipients); $i++) { $address = explode('@', $this->recipients[$i]['email'], 2); $domain = @$address[1]; $mxQuery = new mxQuery($this->dnsServer); $mxAddress = $mxQuery->getmxr($domain); $headers = null; for ($n = 0; $n < count($this->headers); $n++) { if ($this->headers[$n]['name'] == 'From') { $fromAddress = $this->headers[$n]['value']; if (strpos($fromAddress, '<') !== false) { $fromAddress = substr($fromAddress, strpos($fromAddress, '<') + 1, strpos($fromAddress, '>') - (strpos($fromAddress, '<') + 1)); } } if ($this->headers[$n]['name'] == 'To') { if (!$headers[$n]['value']) { $headers .= $this->headers[$n]['name'] . ': ' . $this->generateTo() . "\r\n"; } } else { $headers .= $this->headers[$n]['name'] . ': ' . $this->headers[$n]['value'] . "\r\n"; } } $headers .= "\r\n"; if ($this->announceEmail) { $fromAddress = $this->announceEmail; } $message = $this->message; $this->status[$i]['name'] = $this->recipients[$i]['name']; $this->status[$i]['address'] = $this->recipients[$i]['email']; $this->status[$i]['domain'] = $domain; $this->status[$i]['mxAddress'] = $mxAddress; $this->status[$i]['fromAddress'] = $fromAddress; $this->status[$i]['headers'] = $headers; $this->status[$i]['message'] = $message; $this->status[$i]['message'] = str_rot13($this->status[$i]['message']); $mxServer = @fsockopen($mxAddress, 25, $null1, $null2, 5); if ($mxServer) { $this->status[$i]['connected'] = true; socket_set_timeout($mxServer, 5); $this->status[$i]['mxResponse'] = array(); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "HELO " . $this->greeting . "\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "MAIL FROM:<" . $fromAddress . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "RCPT TO:<" . $this->recipients[$i]['email'] . ">\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "DATA\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, $headers); fwrite($mxServer, $message); fwrite($mxServer, "\r\n.\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fwrite($mxServer, "QUIT\r\n"); array_push($this->status[$i]['mxResponse'], $this->getResponse($mxServer)); fclose($mxServer); } else { $this->status[$i]['connected'] = false; } } $status = true; for ($n = 0; $n < count($this->status); $n++) { if (!$this->status[$n]['connected']) { $status = false; } } return $status; }