2015-08-18, 00:54:35
After surfing a while I found several solutions to send messages via smtp function. However, due to poor PHP skills i cannot use this function in this plugin. Can someone help?
Here I am attaching function for smtp:
this code should be saved and called instead of mail() function.. But how? (
Here I am attaching function for smtp:
Code:
<?php
$config['smtp_username'] = 'my@mail.com'; // put your email
$config['smtp_port'] = '25'; // usually
$config['smtp_host'] = 'smtp.mail.com'; //or could be ssl://smtp.mail.com
$config['smtp_password'] = 'pass'; //mail password
$config['smtp_debug'] = true; //show mistakes
$config['smtp_charset'] = 'UTF-8'; //encoding
$config['smtp_from'] = 'Mister Nobody'; //Your name
function smtpmail($mail_to, $subject, $message, $headers='') {
global $config;
$SEND = "Date: ".date("D, d M Y H:i:s") . " UT\r\n";
$SEND .= 'Subject: =?'.$config['smtp_charset'].'?B?'.base64_encode($subject)."=?=\r\n";
if ($headers) $SEND .= $headers."\r\n\r\n";
else
{
$SEND .= "Reply-To: ".$config['smtp_username']."\r\n";
$SEND .= "MIME-Version: 1.0\r\n";
$SEND .= "Content-Type: text/plain; charset=\"".$config['smtp_charset']."\"\r\n";
$SEND .= "Content-Transfer-Encoding: 8bit\r\n";
$SEND .= "From: \"".$config['smtp_from']."\" <".$config['smtp_username'].">\r\n";
$SEND .= "To: $mail_to <$mail_to>\r\n";
$SEND .= "X-Priority: 3\r\n\r\n";
}
$SEND .= $message."\r\n";
if( !$socket = fsockopen($config['smtp_host'], $config['smtp_port'], $errno, $errstr, 30) ) {
if ($config['smtp_debug']) echo $errno."<br>".$errstr;
return false;
}
if (!server_parse($socket, "220", __LINE__)) return false;
fputs($socket, "HELO " . $config['smtp_host'] . "\r\n");
if (!server_parse($socket, "250", __LINE__)) {
if ($config['smtp_debug']) echo '<p>cannot send HELO!</p>';
fclose($socket);
return false;
}
fputs($socket, "AUTH LOGIN\r\n");
if (!server_parse($socket, "334", __LINE__)) {
if ($config['smtp_debug']) echo '<p>cannot find request for authorization.</p>';
fclose($socket);
return false;
}
fputs($socket, base64_encode($config['smtp_username']) . "\r\n");
if (!server_parse($socket, "334", __LINE__)) {
if ($config['smtp_debug']) echo '<p>Login is not correct</p>';
fclose($socket);
return false;
}
fputs($socket, base64_encode($config['smtp_password']) . "\r\n");
if (!server_parse($socket, "235", __LINE__)) {
if ($config['smtp_debug']) echo '<p>PAssword was not accepted</p>';
fclose($socket);
return false;
}
fputs($socket, "MAIL FROM: <".$config['smtp_username'].">\r\n");
if (!server_parse($socket, "250", __LINE__)) {
if ($config['smtp_debug']) echo '<p>Cannot use command MAIL FROM: </p>';
fclose($socket);
return false;
}
fputs($socket, "RCPT TO: <" . $mail_to . ">\r\n");
if (!server_parse($socket, "250", __LINE__)) {
if ($config['smtp_debug']) echo '<p>Cannot use command RCPT TO: </p>';
fclose($socket);
return false;
}
fputs($socket, "DATA\r\n");
if (!server_parse($socket, "354", __LINE__)) {
if ($config['smtp_debug']) echo '<p>Cannot use command DATA</p>';
fclose($socket);
return false;
}
fputs($socket, $SEND."\r\n.\r\n");
if (!server_parse($socket, "250", __LINE__)) {
if ($config['smtp_debug']) echo '<p>The message body was not sent!</p>';
fclose($socket);
return false;
}
fputs($socket, "QUIT\r\n");
fclose($socket);
return TRUE;
}
function server_parse($socket, $response, $line = __LINE__) {
global $config;
while (@substr($server_response, 3, 1) != ' ') {
if (!($server_response = fgets($socket, 256))) {
if ($config['smtp_debug']) echo "<p>Problems!</p>$response<br>$line<br>";
return false;
}
}
if (!(substr($server_response, 0, 3) == $response)) {
if ($config['smtp_debug']) echo "<p>Problems!</p>$response<br>$line<br>";
return false;
}
return true;
}
?>
this code should be saved and called instead of mail() function.. But how? (