سلام
اين كد رو يادم نيست اصلش رو از كجا دارم !ولي يك ذره اديت هم خودم روش انجام دادم و ازش براي ارسال ايميل از طريق سرويس smtp گوگل استفاده مي كنم . كه يك تابع هست و به راحتي ميتوني براي هر سرويسي استفاده كني ازش
کد PHP:
<?php
function smtp($from, $namefrom, $to, $nameto, $subject, $message, $username, $password, $server = "ssl://smtp.gmail.com", $port = 465 ) {
$newLine = "\r\n";
$smtpConnect = fsockopen($server, $port, $errno, $errstr, 15);
$smtpResponse = fgets($smtpConnect, 515);
if($smtpConnect) {
$logArray['connect'] = $smtpResponse;
}
fputs($smtpConnect, "HELO localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['helo'] = $smtpResponse;
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['auth'] = $smtpResponse;
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['user'] = $smtpResponse;
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['pass'] = $smtpResponse;
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['from'] = $smtpResponse;
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['to'] = $smtpResponse;
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data'] = $smtpResponse;
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=UTF-8" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
fputs($smtpConnect, "To: $to\r\nFrom: $from\r\nSubject: $subject\r\n$headers\r\n\r\n$message\r\n.\r\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['message'] = $smtpResponse;
fputs($smtpConnect, "QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quit'] = $smtpResponse;
//echo nl2br(var_export($logArray));
//print_r($logArray);
}
?>
---------- Post added at 05:56 AM ---------- Previous post was at 05:53 AM ----------
اگر اسكريپت كامل و ajax وزيبا هم ميخواي اين :
گروه نرم افزاری پارس | پروژه ها | ارتباط با ما 1.0 Contact us
رايگان هست و توسط دوست بسيار خوبم آقاي اسكندري در رايت كليك نوشته شده و امكانات بسيار خوبي داره از جمله كد امنيتي و قالب html و smtp دو زبان فارسي و انگليسي و ...