PDA

View Full Version : آموزش: تنظیمات مربوط به فعال سازی تابع mail با اکانت جیمیل در wamp



amin1softco
جمعه 28 مرداد 1390, 12:04 عصر
وقتی شما برنامه وامپ رو نصب می کنید بیشتر چیزایی که لازم دارید رو به صورت لوکال در اختیار شما قرار میده ولی بیشتر اوقات تابع میل با مشکل روبرو می شه یعنی با اخطار معروف زیر نامه ارسال نمی شه

Warning: mail() [function.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 C:\My_Path\send_email.php

من پس از چند جستجویی که انجام دادم به چندتا راه حل رسیدم
1) PHPMailer

Download: http://sourceforge.net/projects/phpmailer

Tutorial: http://phpmailer.codeworxtech.com/index.php?pg=tutorial#2

2) PEAR

Download: http://pear.php.net/package/Mail

Tutorial: http://email.about.com/od/emailprogrammingtips/qt/et073006.htm

3) تغییر تنظیمات
و الان می خوام تغییر تنظیمات رو مرحله به مرحله انجام بدیم تا بتونیم میل رو با استفاده از اکانت جیمیل ارسال کنیم

پیش نیاز این کار دوتا برنامه به نام های sendmail (http://www.glob.com.au/sendmail/sendmail.zip) و stunnel (http://mirror.bit.nl/stunnel/stunnel-4.42-installer.exe) است که اول اینها رو دانلود کنید یا به صورت یکجا از این لینک (https://sites.google.com/site/fileyekja/phpmail.zip) دریافت کنید.

1- نصب و پیکر بندی برنامه sendmail


برای اینکار فایل sendmail.zip را در پوشه wamp اکستراکت کنید که بعد از اکستراکت آدرسش به صورت C:\wamp\sendmail بشه
سپس فایل sendmail.ini رو که در پوشه sendmail قرار گرفته رو باز کنید و به صورت زیر تنظیم کنید.
قسمت هایی که با رنگ آبی مشخص شده رو بدون تغییر وارد کنید و قسمت هایی که با رنگ قرمز مشخص شده بر اساس اکانت جیمیل خودتون کامل کنید :



[sendmail]

; you must change mail.mydomain.com to your smtp server,
; or to IIS's "pickup" directory. (generally C:\Inetpub\mailroot\Pickup)
; emails delivered via IIS's pickup directory cause sendmail to
; run quicker, but you won't get error messages back to the calling
; application.

smtp_server=localhost

; smtp port (normally 25)

smtp_port=25

; SMTPS (SSL) support
; auto = use SSL for port 465, otherwise try to use TLS
; ssl = alway use SSL
; tls = always use TLS
; none = never try to use SSL

smtp_ssl=auto

; the default domain for this server will be read from the registry
; this will be appended to email addresses when one isn't provided
; if you want to override the value in the registry, uncomment and modify

default_domain=gmail.com

; log smtp errors to error.log (defaults to same directory as sendmail.exe)
; uncomment to enable logging

error_logfile=error.log

; create debug log as debug.log (defaults to same directory as sendmail.exe)
; uncomment to enable debugging

debug_logfile=debug.log

; if your smtp server requires authentication, modify the following two lines

auth_username=youracount@gmail.com
auth_password=yourpassword

; if your smtp server uses pop3 before smtp authentication, modify the
; following three lines. do not enable unless it is required.

;pop3_server=pop.gmail.com
;pop3_username=youracount@gmail.com
;pop3_password=yourpassword

; force the sender to always be the following email address
; this will only affect the "MAIL FROM" command, it won't modify
; the "From: " header of the message content

force_sender=youracount@gmail.com

; force the sender to always be the following email address
; this will only affect the "RCTP TO" command, it won't modify
; the "To: " header of the message content

;force_recipient=

; sendmail will use your hostname and your default_domain in the ehlo/helo
; smtp greeting. you can manually set the ehlo/helo name if required

hostname=smtp.gmail.com



2- نصب و پیکر بندی stunnel
برای اینکار شما برنامه stunnel-4.42-installer.exe رو اجرا کنید که در حین نصب یک صفحه سیاه باز می شه که مشخصات کشور و محل زندگی و این چیز های رو می خواهد که مشخصات رو وارد کنید به (صورت غیر واقعی هم وارد کنید مشکلی نداره) سپس از منوی start -> all program -> stunnel -> edit stunnle.cong رو انتخاب کنید و در صفحه تمام تنظیمات رو پاک کنید و اینها رو اونجا کپی و پیست کنید و فایل رو ذخیره کنید.
بعد از اون start -> all program -> stunnel ->service install و سپس service start بروید.




cert = stunnel.pem

socket = l:TCP_NODELAY=1
socket = r:TCP_NODELAY=1

debug = 7
output = stunnel.log

client = yes

[smtpg]
accept = 127.0.0.1:25
connect = smtp.gmail.com:465


; Sample stunnel configuration file for Win32 by Michal Trojnara 2002-2011
; Some options used here may not be adequate for your particular configuration
; Please read the manual and make sure you understand them

; ************************************************** ***************************
; * Global Options *
; ************************************************** ***************************

; Debugging stuff (may useful for troubleshooting)
;debug = 7
;output = stunnel.log

; ************************************************** ***************************
; * Service Defaults (may also be specified in individual service sections) *
; ************************************************** ***************************

; Certificate/key is needed in server mode and optional in client mode
;cert = stunnel.pem
;key = stunnel.pem

; Authentication stuff needs to be configured to prevent MITM attacks
; It is not enabled by default!
;verify = 2
; Don't forget to c_rehash CApath
;CApath = certs
; It's often easier to use CAfile
;CAfile = certs.pem
; Don't forget to c_rehash CRLpath
;CRLpath = crls
; Alternatively CRLfile can be used
;CRLfile = crls.pem

; Disable support for insecure SSLv2 protocol
;options = NO_SSLv2
; Workaround for Eudora bug
;options = DONT_INSERT_EMPTY_FRAGMENTS

; The following options provide additional security at some performance penalty
; Default ECDH/DH parameters are strong/conservative, so it is quite safe to
; comment out these lines in order to get a performance boost
;options = SINGLE_ECDH_USE
;options = SINGLE_DH_USE

; ************************************************** ***************************
; * Service Definitions (at least one service has to be defined) *
; ************************************************** ***************************

; Example SSL server mode services

[pop3s]
accept = 995
connect = 110

[imaps]
accept = 993
connect = 143

[ssmtp]
accept = 465
connect = 25

; Example SSL client mode services

;[gmail-pop3]
;client = yes
;accept = 127.0.0.1:110
;connect = pop.gmail.com:995

;[gmail-imap]
;client = yes
;accept = 127.0.0.1:143
;connect = imap.gmail.com:993

;[gmail-smtp]
;client = yes
;accept = 127.0.0.1:25
;connect = smtp.gmail.com:465

; Example SSL front-end to a web server

;[https]
;accept = 443
;connect = 80
; "TIMEOUTclose = 0" is a workaround for a design flaw in Microsoft SSL
; It does not use SSL close-notify alert designed to prevent truncation attacks
;TIMEOUTclose = 0

; vim:ft=dosini


3- تنظیمات مربوط به فایل php.ini
روی وامپ کلیک کنید و config files -> php.ini را انتخاب کنید و [mail function] را سرچ کنید و تنظیمات رو به صورت زیر تغییر بدید :



[mail function]
; For Win32 only.
;SMTP =

;smtp_port =



; For Win32 only.
;sendmail_from =
; For Unix only. You may supply arguments as well (default: "sendmail -t -i").
sendmail_path ="C:\wamp\sendmail\sendmail.exe -t"

; Force the addition of the specified parameters to be passed as extra parameters
; to the sendmail binary. These parameters will always replace the value of
; the 5th parameter to mail(), even in safe mode.
;mail.force_extra_paramaters =


4- تنظیمات اکانت جیمیل
وارد اكانت جيميل بشيد و smtp رو طبق عكس زير فعال كنيد:

http://www.webdevelopersnotes.com/tips/windows_mail/gmail_pop_access_options.jpg
در آخر یک بار سرویس های وامپ رو ریستارت کنید
منبع (http://digiex.net/guides-reviews/guides-tutorials/application-guides/544-configuring-php-under-windows-use-gmail-external-smtp-server-ssl.html)

amin1softco
جمعه 28 مرداد 1390, 12:14 عصر
برای تستشم می تونید از تابع زیر کمک بگیرید :


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" dir="rtl" lang="fa-IR" id="vbulletin_html">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
</head>
<body>
<?php

$to='yourfriend@yahoo.com';//Enter Your Email Address*
$subject='title';//Subject OF Mail
$from='name';//User Email Address
$message='message of post';//Body Of Mail

// Additional headers
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=utf-8' . "\r\n";
$headers .= 'To: '.$to . "\r\n";
$headers .= 'From: '.$from . "\r\n";
$headers .= 'Reply-To: '.$to . "\r\n";
$headers .= 'X-Mailer: PHP/'. phpversion();
// Mail it
$sendmail=mail($to, $subject, $message, $headers);
if ($sendmail)
echo "نامه شما با موفقت ارسال شد";//Sucess Message
else
echo "در ارسال نامه مشکلي وجود دارد مجدد سعي کنيد";//Failed Message
?>
<body>

Hadis kachal
چهارشنبه 30 شهریور 1390, 16:54 عصر
Warning: mail() [function.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 C:\wamp\www\test\index.php on line 14

من این کار ها رو کردم ولی باز این ارور رو در اجرا بهم میده:عصبانی++: