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; }
<?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>
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; }