PDA

View Full Version : مشکل در اتصال به سرور smtp جیمیل



green.reptile
سه شنبه 21 شهریور 1391, 15:34 عصر
باسلام

بنده جهت ارسال خبرنامه در نظر داشتم تا ایمیل ها رو از طریق سرور جیمیل ارسال کنم اما متاسفانه کامپوننت مورد نظر من (acymailing) با خطای زیر میشه:


Warning: fsockopen() [function.fsockopen (http://www.daliry.com/administrator/function.fsockopen)]: unable to connect to ssl://smtp.gmail.com:465 (Connection timed out) in /home/azadeh/public_html/components/com_acymailing/inc/phpmailer/class.smtp.php on line 123
SMTP -> ERROR: Failed to connect to server: Connection timed out (110)

تنظیمات به این صورت هستش:


Server : smtp.gmail.com
Port :465
Secure Method:SSL
Keep Alive :Yes
Authentication:Yes
Username :greenreptile@gmail.com
Password :XXXXXXX

بمنظور تست اتصال هم کد زیر رو نوشتم:



<?php

$fp = fsockopen("www.google.com", 80, &$errno, &$errstr, 10); // work fine
if(! $fp)
echo "www.google.com - $errstr ($errno)<br>\n";
else
echo "www.google.com - ok<br>\n";


$fp = fsockopen("ssl://smtp.googlemail.com", 465, &$errno, &$errstr, 10); // NOT work
if(! $fp)
echo "ssl://smtp.gmail.com 465 - $errstr ($errno)<br>\n";
else
echo "ssl://smtp.gmail.com 465 - ok<br>\n";


$fp = fsockopen("tls://smtp.gmail.com", 587, &$errno, &$errstr, 10); // NOT work
if(! $fp)
echo "smtp.gmail.com 587 - $errstr ($errno)<br>\n";
else
echo "smtp.gmail.com 587 - ok<br>\n";

echo "<br />".phpinfo();
?>



که این کد هم همون خطا رو میده:
http://www.daliry.com/test/connect.php

پشتیبانی هاست ایران هم اعلام کرده که پورت 465 outbound باز هستش
(متاسفانه سرور ssh روبسته و نمیتونم با puty تست بگیرم واسه telnet و تست بازبودن پورت ) واسه همین این کد رو نوشتم:




<?php
$fp = fsockopen('127.0.0.1', 465, $errno, $errstr, 5);
if (!$fp) {
echo "port 465 is closed or blocked";
} else {
// port is open and available
echo "port 465 is open";
fclose($fp);
}
?>


و نتیجه :
http://www.daliry.com/test/port.php


مشکل از چی میتونه باشه؟
(لازم به ذکره که با همین تنظیمات نرم افزار تحت ویندوز groupmail5 کار میکنه و مشکلی نداره)

tehro0n
سه شنبه 21 شهریور 1391, 21:58 عصر
این ارسال رو امتحان کن
فقط در اول کد ip و ایمیل و پسوردت رو یادت نره وارد کنی


<?php
function authgMail($from, $namefrom, $to, $nameto, $subject, $message)
{
$smtpServer = "tls://smtp.gmail.com"; //does not accept STARTTLS
$port = "465"; // try 587 if this fails
$timeout = "45"; //typical timeout. try 45 for slow servers
$username = "greenreptile@gmail.com"; //your gmail account
$password = "xxxx"; //the pass for your gmail
$localhost = "YOUR IP"; //$_SERVER['REMOTE_ADDR']; //requires a real ip
$newLine = "\r\n"; //var just for newlines
/* you shouldn't need to mod anything else */
//connect to the host and port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
//echo $errstr." - ".$errno;
$smtpResponse = fgets($smtpConnect, 4096);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
//echo $output;
return $output;
}
else
{
$logArray['connection'] = "Connected to: $smtpResponse";
//echo "connection accepted".$smtpResponse."<p />Continuing<p />";
//echo $tadr;
}
//you have to say HELO again after TLS is started
fputs($smtpConnect, "HELO $localhost". $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['heloresponse2'] = "$smtpResponse";
//request for auth login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authrequest'] = "$smtpResponse";
//send the username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authusername'] = "$smtpResponse";
//send the password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['authpassword'] = "$smtpResponse";
//email from
fputs($smtpConnect, "MAIL FROM: <$from>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailfromresponse'] = "$smtpResponse";
//email to
fputs($smtpConnect, "RCPT TO: <$to>" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['mailtoresponse'] = "$smtpResponse";
//the email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['data1response'] = "$smtpResponse";
//construct headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto $to1" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;
//observe the . after the newline, it signals the end of message
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, 4096);
$logArray['data2response'] = "$smtpResponse";
// say goodbye
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 4096);
$logArray['quitresponse'] = "$smtpResponse";
$logArray['quitcode'] = substr($smtpResponse,0,3);
fclose($smtpConnect);
//a return value of 221 in $retVal["quitcode"] is a success
$a='Mail Sent Sucessfully';
return($a);
}
$from = 'info@toolsir.com';
$namefrom = 'Arman Rezaei';
$to = 'greenreptile@gmail.com';
$nameto = 'Nima';
$subject = 'Salam';
$message = 'chetori? khoobi';

authgMail($from, $namefrom, $to, $nameto, $subject, $message);
?>

green.reptile
چهارشنبه 22 شهریور 1391, 15:39 عصر
باتشکر
این هم کد شما:
http://www.daliry.com/test/3.php

متاسفانه تابع fsockopen نمیتونه وصل بشه به سرور!
آیا ممکنه مشکل از خود فایروال سرور جیمیل باشه؟