Пример #1
0
function sendEmail($subject, $content, $emailto, $emailfrom)
{
    $from = $emailfrom;
    $response_sent = 'Thank you. Your comments have been received.';
    $response_error = 'Error. Please try again.';
    $subject = filter($subject);
    $url = "Origin Page: " . $_SERVER['HTTP_REFERER'];
    $ip = "IP Address: " . $_SERVER["REMOTE_ADDR"];
    $message = $content . "\n{$ip}\r\n{$url}";
    // Validate return email & inform admin
    $emailto = filter($emailto);
    // Setup final message
    $body = wordwrap($message);
    if ($use_smtp == '1') {
        $SmtpServer = 'SMTP SERVER';
        $SmtpPort = 'SMTP PORT';
        $SmtpUser = '******';
        $SmtpPass = '******';
        $to = $emailto;
        $SMTPMail = new SMTPClient($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
        $SMTPChat = $SMTPMail->SendMail();
        $response = $SMTPChat ? $response_sent : $response_error;
    } else {
        // Create header
        $headers = "From: {$from}\r\n";
        $headers .= "MIME-Version: 1.0\r\n";
        $headers .= "Content-type: text/plain; charset=utf-8\r\n";
        $headers .= "Content-Transfer-Encoding: quoted-printable\r\n";
        // Send email
        $mail_sent = @mail($emailto, $subject, $body, $headers);
        $response = $mail_sent ? $response_sent : $response_error;
    }
    return $response;
}
Пример #2
0
<?php

include 'SMTPconfig.php';
include 'SMTPClass.php';
if ($_SERVER["REQUEST_METHOD"] == "POST") {
    $to = $_POST['to'];
    $from = $_POST['from'];
    $subject = $_POST['sub'];
    $body = $_POST['message'];
    $SMTPMail = new SMTPClient($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $from, $to, $subject, $body);
    $SMTPChat = $SMTPMail->SendMail();
}
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>

<body>
<form method="post" action="">
<table width="500px">
<tr><td width="20%">To : </td>
<td ><input type="text" name="to" /></td></tr>
<tr><td>From :</td><td><input type='text' name="from" /></td></tr>
<tr><td>Subject :</td><td><input type='text' name="sub" /></td></tr>
<tr><td>Message :</td><td><textarea name="message"></textarea></td></tr>
<tr><td></td><td><input type="submit" value=" Send " /></td></tr>
</table>
Пример #3
0
 /**
  * Sends the command to the server and reads the response to it. 
  * 
  * @param string|NULL|array $command The command to send (can use printf 
  *                                   style). If NULL, no command is sent 
  *                                   and this just reads a server response.
  *                                   If it is an array, all items will be 
  *                                   treated like lines of commands and
  *                                   will be sent to the server while the
  *                                   response will be read only after all
  *                                   of them are sent.
  * @param mixed $args,... Optional printf-like arguments
  *
  * @return Response The server response
  *
  * @throws InvalidStateException If the communicator is not connected
  * @throws InvalidArgumentException If printf-like arguments are used for
  *                                  non-textual command (ie. array command)
  * @throws IOException If writing or reading over network failed
  */
 public function getResponse($command)
 {
     if ($this->connection === NULL) {
         throw new InvalidStateException('Cannot communicate with SMTP ' . 'server when not connected.');
     }
     if ($command !== NULL) {
         if (func_num_args() > 1) {
             if (!is_string($command)) {
                 throw new InvalidArgumentException('Cannot use printf-like arguments to a command which' . ' is not a string!');
             }
             $args = func_get_args();
             array_shift($args);
             $command = vsprintf($command, $args);
         }
         if (!is_array($command)) {
             $command = array($command);
         }
         foreach ($command as $line) {
             //send the command to the server
             SMTPClient::debug("\n\nCOMMAND: %s\n=======", $line);
             if (@fwrite($this->connection, $line . self::EOL) === FALSE) {
                 if (@fwrite($this->connection, $line . self::EOL) === FALSE) {
                     throw new IOException('Could not send the command to the ' . 'server: ' . $command);
                 }
             }
         }
     }
     /*
      * The reply text may be longer than a single line; in these cases the
      * complete text must be marked so the SMTP client knows when it can
      * stop reading the reply.  This requires a special format to indicate a
      * multiple line reply.
      *
      * The format for multiline replies requires that every line, except the
      * last, begin with the reply code, followed immediately by a hyphen,
      * "-" (also known as minus), followed by text.  The last line will
      * begin with the reply code, followed immediately by <SP>, optionally
      * some text, and <CRLF>.  As noted above, servers SHOULD send the <SP>
      * if subsequent text is not sent, but clients MUST be prepared for it
      * to be omitted.
      *
      * For example:
      *
      *    123-First line
      *    123-Second line
      *    123-234 text beginning with numbers
      *    123 The last line
      *
      * In many cases the SMTP client then simply needs to search for a line
      * beginning with the reply code followed by <SP> or <CRLF> and ignore
      * all preceding lines.  In a few cases, there is important data for the
      * client in the reply "text".  The client will be able to identify
      * these cases from the current context.
      */
     $response['code'] = '';
     $response['text'] = array();
     $responsePart = '';
     $i = 0;
     //we fetch lines of the response
     while ($line = fgets($this->connection, self::MAX_RESPONSE_LENGTH)) {
         //fgets leaves the CRLF at the end of the string
         $line = rtrim($line);
         //blank line shouldn't appear, it indicates nothing more is to
         //be read
         if (strlen($line) < 3) {
             break;
         }
         //if we loop a lot of times, something went wrong, so
         //give up the reading
         if ($i > self::MAX_RESPONSE_LINES) {
             throw new InvalidStateException('There was a problem reading server response. The client' . 'could not detect its end.');
         }
         SMTPClient::debug('RESPONSE LINE #%u: %s', ++$i, $line);
         //first 3 charachters denote the response code
         $response['code'] = substr($line, 0, 3);
         //and everything after the 4th character is the response text
         //note that the response text can be empty, in that case the
         //response text will be false ( @see substr() )
         $response['text'][] = substr($line, 4);
         //If we encountered a response, where space follows response code,
         //it is the last line. Other lines have a hyphen (-) instead
         if (substr($line, 3, 1) == ' ') {
             break;
         }
     }
     $this->lastResponse = new Response((int) $response['code'], $response['text']);
     return $this->lastResponse;
 }
Пример #4
0
function SendMail($MailTo, $Subject, $BodySTR)
{
    extract($GLOBALS, EXTR_REFS);
    $SMTPMail = new SMTPClient($SmtpServer, $SmtpPort, $SmtpUser, $SmtpPass, $SmtpUser, $MailTo, $Subject, $BodySTR);
    $SMTPChat = $SMTPMail->SendMail();
    return true;
}
Пример #5
0
<?php

include "SMTPClient.php";
$smtpClient = new SMTPClient();
$smtpClient->setServer("smtp.gmail.com", "465", "tls");
$smtpClient->setSender("*****@*****.**", "*****@*****.**", "mypassword");
$smtpClient->setMail("mybestfriend@example.com, john.smith@example.com", "My first email with SMTPClient", "Hi folks,\nif you can read that, it means that my SMTPClient" . " is working.");
$smtpClient->attachFile("Text.txt", "Text file content example");
$smtpClient->attachFile("Image.PNG", file_get_contents("./brae.png"));
$smtpClient->sendMail();