PDA

View Full Version : ارسال ایمیل به دانشجویان از طریق mailserver دانشگاه



neda_barnamenevis
یک شنبه 23 مهر 1391, 13:44 عصر
من می خواهم به دانشجویان پیغام بدهم که شما ثبت نام کردید اما می خواهم از طریق mail server دانشگاه انجام بدهم
کسی کدش را داره
فقط این را می دونم که از طریق pop3 باید انجام بدهم اما نمی دانم چکونه

tehro0n
یک شنبه 23 مهر 1391, 15:39 عصر
این نمونه برای میل سرور گوگل هست که اطلاعات کاربری رو باید پر کنی
اگه حتما می خواهی از میل سرور دانشگاه انجام بدی که smtp دانشگاهتون رو باید بدونی، بعید می دونم دانشگاه خودش داشته باشه!
ولی اگه می خواهی نام دانشگاه و ایمیل دانشگاه رو می خواهی در عنوان قرار بدی که می تونی از همین گوگل استفاده کنی و در پایین کد تغییرات لازمه را بدهی

<?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 = ""; //your gmail account
$password = ""; //the pass for your gmail
$localhost = ""; //$_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 = 'nima@yahoo.com';
$nameto = 'Nima';
$subject = 'Salam';
$message = 'chetori? khoobi';

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

Unique
دوشنبه 24 مهر 1391, 00:59 صبح
من بعدی میدونم یاهو و Gmail ایمیل های ارسالی از سرور های ایران را توی Inbox قرار بدهند یا اصلا کلا deliver کنند ! کسی تا حالا این کار را کرده ؟! یعنی از هاست های ایران تونسته ایمیل بفرسته ؟

neda_barnamenevis
دوشنبه 24 مهر 1391, 08:24 صبح
خوب به جای smpt نمی توان از ip mail server استفاده کرد؟




این نمونه برای میل سرور گوگل هست که اطلاعات کاربری رو باید پر کنی
اگه حتما می خواهی از میل سرور دانشگاه انجام بدی که smtp دانشگاهتون رو باید بدونی، بعید می دونم دانشگاه خودش داشته باشه!
ولی اگه می خواهی نام دانشگاه و ایمیل دانشگاه رو می خواهی در عنوان قرار بدی که می تونی از همین گوگل استفاده کنی و در پایین کد تغییرات لازمه را بدهی

<?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 = ""; //your gmail account
$password = ""; //the pass for your gmail
$localhost = ""; //$_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 = 'nima@yahoo.com';
$nameto = 'Nima';
$subject = 'Salam';
$message = 'chetori? khoobi';

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

tehro0n
سه شنبه 25 مهر 1391, 01:16 صبح
مشکلی پیش نمیاد و به inbox میره و خط پایین برای آی پی شماست


$localhost = ""; //$_SERVER['REMOTE_ADDR']; //requires a real ip

با این کار شما می تونید 500 ایمیل در روز ارسال کنید، اگه بیشتر می خوای از چند اکانت استفاده کن و سوییچ کن


مواردی که باعث میشن به این باکس نره میشه گفت اینجور چیزاست
استفاده از عکس ها
حجم زیاد میل
نداشتن نام ارسال کننده یا گیرنده
نداشتن موضوع
و ..

Unique
سه شنبه 25 مهر 1391, 01:43 صبح
دوست عزیز در مورد gmail صحبت نکردند ها ! گفتن از mail server دانشگاه و نه mail server شرکت گوگل !!

neda_barnamenevis
سه شنبه 25 مهر 1391, 10:36 صبح
من smtp دانشگاه را دارم فقط این قسمت را باید تغییر بدهم ؟

$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 = ""; //your gmail account
$password = ""; //the pass for your gmail
$localhost = ""; //$_SERVER['REMOTE_ADDR']; //requires a real ip



port , timeout را چی بزنم؟


فقط همین ۲ قسمت باید تغییر کند درست است؟

$from = 'info@toolsir.com';
$namefrom = 'Arman Rezaei';
$to = 'nima@yahoo.com';
$nameto = 'Nima';
$subject = 'Salam';
$message = 'chetori? khoobi';

tehro0n
سه شنبه 25 مهر 1391, 18:35 عصر
دوست عزیز در مورد gmail صحبت نکردند ها ! گفتن از mail server دانشگاه و نه mail server شرکت گوگل !!
من هم اولین پستم در این مورد که برای چه کاری می خواهید صحبت کردم و ادامه دادم! و اینکه این تابع برای ارسال تمامی میل سرورها کاربرد داره، شما جی میل نمی خواهید تغییر بدید!

timeout همین 45 خوبه، و پورت هم باید پورت دانشگاه باشه، 465 و 587 برای جی میل است، یک پورت آزاد پیدا کنید.. اگه هم دانشگاه میل سرور داره از همان پورت استفاده کنید

neda_barnamenevis
دوشنبه 01 آبان 1391, 14:39 عصر
من با smtp دانشگاه تست کردم می نویسه که ایمیل ارسال شد
ولی وقتی ایمیل جیمیل خودم را به عنوان نمونه دادم نمی فرسه به نظر شما چرا
آیا باید در لینوکس (centos)چیزی را فعال کنم؟

Unique
سه شنبه 02 آبان 1391, 01:54 صبح
همونطور که گفتم بعید میدونم yahoo و gmail ایمیل های ارسالی از ip های ایران را deliver کنند ! حداقل من تجربه اش را نداشتم ! دوستان اگه کسی تا الا با ip valid ایران تونسته یه خبری بده !

neda_barnamenevis
سه شنبه 02 آبان 1391, 08:00 صبح
$localhost را چی باید بزنیم ؟ ip میل سرور و یا 127.0.0.1

neda_barnamenevis
سه شنبه 02 آبان 1391, 14:52 عصر
وقتی اجرا می کنم یک error هم دارد چرا؟
Undefined variable: to1 in /var/www/html/8.php on line 59