PDA

View Full Version : آموزش: ارسال ایمیل فارسی با PHP



alonemm
سه شنبه 06 مهر 1389, 09:09 صبح
با سلام خدمت دوستان:

دیدم که خیلی از دوستان با این موضوع مشکل دارند که این فایل رو واسشون آماده کردم.
توی فایل ضمیمه یک فایل PHP گزاشتم که ارسال ایمیل رو به صورت فارسی انجام میده.
تستش هم کردم.

اگه هر سوال یا خطی از کد رو کارشرو ندونستید بگید راهنمایی کنم.


موفق باشید.

saeid_k121
دوشنبه 22 آذر 1389, 21:53 عصر
سلام ... مرسی از زحمتی که کشیدین ...

من یه مشکلی دارم که البته شاید خیلی مرتبط با این مبحث نباشه ولی چون از همین کد استفاده کردم می پرسم ... من موفق شدم ایمیل ارسال کنم و فارسی هم شد به لطف شما ولی نکته عجیب اینه که از هر ایمیل 2تا ارسال میشه !!!! یعنی توی INBOX دوتا ایمیل عین هم و همزمان میآد !!! کسی میتونه کمکم کنه این مشکل رو حل کنم !؟!؟ اصلا ایده ای ندارم که چطور اینجوری میشه !!!!!!!!

Homayoon-T
سه شنبه 07 دی 1389, 19:19 عصر
دوستان من این کد رو اجرا کردم ولی این Error رو داد :

Notice: Undefined index: email in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 4

Notice: Undefined variable: to in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 6

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 47
پیام ارسال نشد!

MSN_Issue
سه شنبه 07 دی 1389, 20:33 عصر
دوست عزیز میل سرور یاهو توانایی دریافت ایمیلهای ارسال شده با تابع mail رو نداره !!!
روش دیگه ای برای ارسال بلد نیستید ؟! ( مثل pop3 یا ... )
اگه کسی نمونه کد داشت ممنون میشم بذاره .

alonemm
سه شنبه 07 دی 1389, 21:27 عصر
من به سرور ياهو هم فرستادم با همين كد به قسمت Inbox هم ارسال شده.

alonemm
سه شنبه 07 دی 1389, 21:29 عصر
دوستان من این کد رو اجرا کردم ولی این Error رو داد :

Notice: Undefined index: email in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 4

Notice: Undefined variable: to in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 6

Warning: mail(): Failed to connect to mailserver at "localhost" port 25, verify your "SMTP" and "smtp_port" setting in php.ini or use ini_set() in d:\easyphp1-8\www\utf8-email\funsendmail.php on line 47
پیام ارسال نشد!

مشكل از درگاه SMTP شما هست كه باز نيست.

Vahid Faraji
سه شنبه 07 دی 1389, 23:02 عصر
روش یک:


PHP script sending with external SMTP authentication (http://www.onlinehowto.net/Tutorials/PHP/PHP-script-sending-with-external-SMTP-authentication/1443)


روش دو:


PHP Mail Script with SMTP Authentication:

The below email script is for PHP emailing with SMTP authentication.



<?php
//new function
$to = "you@your-domainname.com";
$nameto = "Who To";
$from = "script@your-domainname.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//This will send an email using auth smtp and output a log array
//logArray - connection,

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "mail.ukdns.biz";
$port = "25";
$timeout = "30";
$username = "your-email-address@domain.com";
$password = "Your-POP3-Password";
$localhost = "mail.ukdns.biz";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */

//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
?>


اینم لینکش:

PHP Mail Script with SMTP Authentication (http://support.webecs.com/KB/a390/php-mail-script-with-smtp-authentication.aspx)

رضا قربانی
دوشنبه 13 دی 1389, 19:25 عصر
روش یک:


PHP script sending with external SMTP authentication (http://www.onlinehowto.net/Tutorials/PHP/PHP-script-sending-with-external-SMTP-authentication/1443)


روش دو:


PHP Mail Script with SMTP Authentication:

The below email script is for PHP emailing with SMTP authentication.



<?php
//new function
$to = "you@your-domainname.com";
$nameto = "Who To";
$from = "script@your-domainname.com";
$namefrom = "Who From";
$subject = "Hello World Again!";
$message = "World, Hello!";
authSendEmail($from, $namefrom, $to, $nameto, $subject, $message);
?>


<?php
/* * * * * * * * * * * * * * SEND EMAIL FUNCTIONS * * * * * * * * * * * * * */

//This will send an email using auth smtp and output a log array
//logArray - connection,

function authSendEmail($from, $namefrom, $to, $nameto, $subject, $message)
{
//SMTP + SERVER DETAILS
/* * * * CONFIGURATION START * * * */
$smtpServer = "mail.ukdns.biz";
$port = "25";
$timeout = "30";
$username = "your-email-address@domain.com";
$password = "Your-POP3-Password";
$localhost = "mail.ukdns.biz";
$newLine = "\r\n";
/* * * * CONFIGURATION END * * * * */

//Connect to the host on the specified port
$smtpConnect = fsockopen($smtpServer, $port, $errno, $errstr, $timeout);
$smtpResponse = fgets($smtpConnect, 515);
if(empty($smtpConnect))
{
$output = "Failed to connect: $smtpResponse";
return $output;
}
else
{
$logArray['connection'] = "Connected: $smtpResponse";
}

//Request Auth Login
fputs($smtpConnect,"AUTH LOGIN" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authrequest'] = "$smtpResponse";

//Send username
fputs($smtpConnect, base64_encode($username) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authusername'] = "$smtpResponse";

//Send password
fputs($smtpConnect, base64_encode($password) . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['authpassword'] = "$smtpResponse";

//Say Hello to SMTP
fputs($smtpConnect, "HELO $localhost" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['heloresponse'] = "$smtpResponse";

//Email From
fputs($smtpConnect, "MAIL FROM: $from" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailfromresponse'] = "$smtpResponse";

//Email To
fputs($smtpConnect, "RCPT TO: $to" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['mailtoresponse'] = "$smtpResponse";

//The Email
fputs($smtpConnect, "DATA" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data1response'] = "$smtpResponse";

//Construct Headers
$headers = "MIME-Version: 1.0" . $newLine;
$headers .= "Content-type: text/html; charset=iso-8859-1" . $newLine;
$headers .= "To: $nameto <$to>" . $newLine;
$headers .= "From: $namefrom <$from>" . $newLine;

fputs($smtpConnect, "To: $to\nFrom: $from\nSubject: $subject\n$headers\n\n$message\n.\n");
$smtpResponse = fgets($smtpConnect, 515);
$logArray['data2response'] = "$smtpResponse";

// Say Bye to SMTP
fputs($smtpConnect,"QUIT" . $newLine);
$smtpResponse = fgets($smtpConnect, 515);
$logArray['quitresponse'] = "$smtpResponse";
}
?>


اینم لینکش:

PHP Mail Script with SMTP Authentication (http://support.webecs.com/KB/a390/php-mail-script-with-smtp-authentication.aspx)
داداش این دوتا رو ارور می گیره :

$smtpServer = "mail.ukdns.biz";

$localhost = "mail.ukdns.biz";


Warning: fsockopen() [function.fsockopen (http://localhost/sama/function.fsockopen)]: unable to connect to mail.ukdns.biz:25 (A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond. ) in C:\xampp\htdocs\sama\funsendmail.php on line 33

Warning: fgets(): supplied argument is not a valid stream resource in C:\xampp\htdocs\sama\funsendmail.php on line 34

alonemm
سه شنبه 14 دی 1389, 18:10 عصر
براي باز كردن اين درگاه (SMTP ):
1- فايروال روي سيستم به اين قسمت رو از حالت Enabel دربياريد.
2- از نرم افزار هايي مانند SMTP Server استفاده كنيد و اونه به حالت Start دربياريد.
3- اتصال به انترنت رو چك كنيد كه پاكت هايي ارسالي داشته باشيد.

رضا قربانی
سه شنبه 14 دی 1389, 18:23 عصر
3- اتصال به انترنت رو چك كنيد كه پاكت هايي ارسالي داشته باشيد.

منظورتمون رو متوجه نشدم

؟

alonemm
سه شنبه 14 دی 1389, 18:46 عصر
كه اطلاعات شما ارسال ميشود.
با دستور Ping 4.2.2.4

رضا قربانی
سه شنبه 14 دی 1389, 22:36 عصر
2- از نرم افزار هايي مانند SMTP Server استفاده كنيد و اونه به حالت Start دربياريد.

می شه این نرم افزار رو اینجا برامون بذارید تا من و بقیه دوستان که این مشکل رو دارند حل بشه :قلب:

Vahid Faraji
سه شنبه 14 دی 1389, 23:07 عصر
می شه این نرم افزار رو اینجا برامون بذارید تا من و بقیه دوستان که این مشکل رو دارند حل بشه :قلب:

به این لینک مراجعه نمائید.

http://www.softstack.com/freesmtp.html

maryam_saboori
یک شنبه 04 آبان 1393, 12:07 عصر
اگر که با نحوه استفاده و کانفیگ smtp آشناییی ندارید میتونید ازین فیلم آموزشی : clicksite.ir/article.php?id=74 که نحوه کار با phpmailer و smtp رو کامل به زبان فارسی توضیح داده هم استفاده کنید.
اقداماتی از جمله چک کردن صحت میل سرور smtp و هم چنین بررسی باز بودن پورت های مربوط به smtp رو هم توضیح داده که جامع و کامله و امیدوارم مشکلتون رو حل کنه.

hooshmanddtnet
یک شنبه 24 آبان 1394, 19:15 عصر
با سلام
کسی میدونه مشکل از کجاست ؟
دوستان کدی که برای فرم تماس با ما نوشتم و قبلا روی یه هاست دیگه درست کار می کرد متاسفانه روی هاست جدید فقط اگر آدرس فرستنده ایمیل (SetFrom) با گیرنده ایمیل یکی باشه ، ایمیل ارسال میشه و گرنه از آدرس فرستنده خطا می گیره ، چه باید کرد؟ .