Daim ntawv foos tawm tswv yim yog qhov tseem ceeb ntawm kev xaib ntawm txhua lub xaib tsim los daws cov teeb meem loj. Ib txoj hauv kev yooj yim tshaj plaws los npaj email los ntawm tus xaib rau tus tswv rau nws tus kheej yog siv PHP mail kev hais kom ua. Hauv qab no yog cov lus qhia ib qib-qib-qib qhia txog kev ua li cas.
Nws yog qhov tsim nyog
Yooj yim kev paub lus PHP thiab HTML
Cov Lus Qhia
Kauj ruam 1
Kauj ruam 1: tsim daim ntawv php tshiab.
Hauv txhua cov ntawv kho nyeem (piv txwv, hauv tus qauv Notepad) tsim cov ntawv tshiab. Tam sim ntawd nkag mus rau hauv nws tus ncej ntawm html-code ntawm nplooj ntawv, uas koj yuav ntxiv thaum lub sijhawm tsim cov txheej txheem rau kev xa email:
Xa ib cov e-mail xov
Kauj ruam 2
Kauj ruam 2: ntxiv daim ntawv html rau koj daim ntawv.
Tam sim no koj xav tau ntxiv ntawm cov html cim npe thiab cov lus qhia rau lub browser kom pom daim ntawv foos rau tus qhua nkag mus nkag cov ntaub ntawv thiab xa mus rau tus neeg rau zaub mov. Ua ntej, daim pib qhib ntawm daim foos:
Cov txheej txheem cwj pwm tau txheeb xyuas seb qhov browser yuav xa cov ntaub ntawv xa mus rau server li cas.
Ntawm no koj yuav tsum ntxig ib qho kev qhia hauv php - nws yuav qhia cov lus rau tus qhua tom qab nws xa cov ntaub ntawv mus rau server thiab lawv tau ua tiav los ntawm tsab ntawv:
Cov kab txuas ntxiv tuaj yeem ua daim teb uas cov qhua yuav tsum sau nws lub npe:
Koj lub npe:
Ntawm no hom ntaus ntawv qhia meej cov hom ntawv tsim qauv no - lub thawv ntawv yooj yim. Thiab lub npe cwj pwm yog lub npe ntawm cov sib txawv uas cov nkag rau hauv daim teb no yuav kis mus rau server - npe. Tag
- "Lub tsheb xa rov qab".
Tom ntej no, koj yuav tsum muab lub sijhawm rau tus qhua nws sau nws chaw nyob hauv email rau nws:
Email:
Txhua yam ntawm no zoo ib yam li rau kab yav dhau los. Lub npe ntawm cov sib txawv uas email chaw nyob ntawm tus qhua yuav raug xa mus rau tus neeg rau zaub mov yog email.
Tam sim no peb xav tau ntxiv cov lus sau ua ntau nplooj ua ntej (textarea tag) kom nkag mus rau kab ntawv kab ntawv:
Xov:
Cov kab thiab cols cov cwj pwm qhia qhov loj me ntawm daim teb no - kab qhia txog tus naj npawb ntawm cov kab, thiab cols qhia txog tus naj npawb ntawm cov cim hauv txhua kab. Cov ntawv sau nkag yuav muab xa hauv qhov sib txawv npe hu ua mess.
Tom qab txhua daim teb, ntxiv lub pob kom xa lus:
Tus nqi ntaus nqi ntawm cov cim npe no muaj cov ntawv sau ntawm daim ntawv lo ntawm pob ("Xa").
Rau cov ntawv php los ua haujlwm, ib tus xav paub ntau ntxiv yuav tsum tau, uas yuav tsum tau xa nrog cov ntaub ntawv los ntawm daim ntawv. Muab nws tso rau hauv ib daim foos zais ntawm tus qhua:
Lub npe ntawm cov sib txawv no yog "ua" thiab tus nqi dhau los yog "xa".
Qhov tsuas yog ua rau sab laug yog ntxiv rau daim ntawv kaw cim npe:
Kauj ruam 3
Kauj Ruam 3: ntxiv php code cov txheej txheem los ua cov ntaub ntawv los ntawm daim foos.
Los ntawm nias lub pob sau npe "Xa", tus qhua yuav xa cov ntaub ntawv nkag los ntawm nws. Vim tias tsis muaj kev ntaus nqi rau hauv daim foos, uas yuav tsum qhia qhov chaw nyob hauv Internet ntawm tsab ntawv xa cov ntaub ntawv, lawv yuav raug xa mus rau qhov chaw nyob ntawm tib nplooj ntawv. Yog li, koj yuav tsum ntxiv cov lus qhia php rau html-code ntawm nplooj ntawv no kom tau txais, lees paub thiab xa cov ntaub ntawv los ntawm daim foos rau koj email chaw nyob.
Lawv yuav tsum pib nrog qhib php lossis:
<? php
Ntawm kab txuas ntxiv, sau lub npe sib txawv uas yuav muaj kab lus rau tus qhua. Thaum lub sij hawm npliag:
$ msg = ;
Tam sim no tsab ntawv yuav tsum kos yog tias cov ntaub ntawv raug xa los ntawm daim ntawv. Tus neeg rau zaub mov, txais cov ntaub ntawv xa los ntawm POST txujci, muab tso rau hauv superglobal array uas muaj npe $ _POST. Yog li cov ntawv xav tau tshawb xyuas yog tias muaj cov ntaub ntawv los ntawm daim ntawv hauv no array. Tus qhua tuaj yeem tsis tau sau hauv daim teb, tab sis tus muab zais tsis sib xws yuav tsum tseem nyob - peb yuav kuaj nws qhov chaw nyob:
yog ($ _ POST ['ua'] == "xa") {
Yog tias muaj qhov sib xws, tom qab ntawv thaiv ntawm cov ntawv qhia yuav raug tua. Rau kev yooj yim, thaum pib ntawm lub block, tso cov qhob uas koj tuaj yeem hloov kho tom qab:
$ email_length = 500;
Qhov no yog qhov ntau tsawg kawg ntawm lub cim tso cai nyob rau hauv tus qhua cov lus.
$ email_html = cuav;
Yog tias tus neeg siv nkag ntawm html tags hauv cov lus, lawv yuav raug txiav los ntawm tsab ntawv. Yog tias lawv yuav tsum tau sab laug, tom qab ntawd hloov qhov tsis tseeb ntawm tus nqi no nrog qhov tseeb.
$ email_recepient = "[email protected]";
Nov yog koj email chaw nyob uas tsab ntawv yuav tsum xa cov lus los ntawm cov neeg tuaj saib.
$ email_subject = "Cov lus los ntawm tus xaib site";
Cov hloov pauv muaj cov kab ntawv uas yuav qhia hauv kab ntawv ntawm tus email xa rau koj.
$ email_regex = "/ ^ (([^ () .,;:: s @ "] + (. [^ () .,;: / s @ "] +) *) | (". + ")) @ (([0-9] {1, 3}. [0-9] {1, 3}. [0-9] {1, 3}. [0-9] {1, 3}]) | (([a-zA-Z / -0-9] + \.) + [A-zA-Z] {2,})) $ / ";
Cov hloov pauv no yuav tsum tsis txhob hloov - nws muaj cov qauv lus niaj zaus uas siv los ntawm tsab ntawv los sau cov hom phiaj ntawm email chaw nyob uas nkag los ntawm tus qhua nyob hauv qhov chaw email. Cov kab tom ntej yuav muaj daim tshev no:
yog ((!!
Yog tias tus qhua tau hais meej qhov chaw nyob tsis zoo rau kev sib cuag nws, tsab ntawv yuav ua ib qho xov qhia txog qhov no. Txhua cov lus zoo li no tau raug suav nrog hauv $ msg kuj sib txawv thiab kom txog rau thaum kawg ntawm tsab ntawv.
Tam sim no tshawb xyuas qhov kuaj pom ntawm kab ntawv cov ntawv nws tus kheej:
yog (! $ _ POST ['mess']) $ msg. = "Tsis muaj ntawv sau lus";
Yog tias tus qhua qhua cov ntawv sau khoob, tom qab ntawv sau txog qhov no yuav muab ntxiv rau $ msg kuj sib txawv thiab.
Yog tias nyob hauv $ email_html kuj sib txawv koj tau teev kev tshem tawm ntawm html cov ntawv los ntawm cov lus ntawv, ces tsab ntawv yuav ua qhov no hauv ob kab hauv qab no:
$ userMess = $ _POST ['mess'];
yog (! $ email_html) $ userMess = strip_tags ($ userMess);
Thiab tom kawg ntawm txhua daim tshev - xyuas cov lus ntev:
yog tias (strlen ($ userMess)> $ email_length) $ msg. = "Cov lus sau yog ntev dua li qhov tau tso cai ntev ($ email_length cim).
n ;
Yog tias tsawg kawg ib qho ntawm qhov kev ntsuam xyuas tsis tau dhau los, ces tus lej $ msg kuj tsis paub meej li lawm. Tom qab ntawd koj yuav tsum ua tiav tag nrho cov ntawv sau yuam kev uas tau sau rau hauv nws - ntxiv cov ntawv sau "Yuam kev" thiab teeb ntxoov liab:
yog tias ($ msg) $ msg = "Yuam Kev: $ msg";
Thiab yog tias cov tshev dhau los, tom qab ntawd npaj cov ntaub ntawv xa rau koj qhov chaw nyob:
lwm {
$ userMess = "Npe:". $ _ NCEJ ['npe']."
n ---
n ". $ userMess."
n
n ---
n ;
$ headers = "Cov Ntsiab Lus-Hom: ntawv nyeem / html; charset = windows-1251 / n";
$ headers. = "Los ntawm: / nX-Tus xa ntawv: siteMailer";
Cov kab tom ntej pib koj lub server mailer thiab xa cov lus npaj:
xa ntawv ($ email_recepient, $ email_subject, $ userMess, $ headers);
Tam sim no nws tseem nyob rau hauv los sau lus rau cov qhua uas nws cov lus tau xa:
$ msg = Koj cov lus tau raug xa mus. Ua tsaug!
n ;
}
}
?>
Kauj ruam 4
Kauj ruam 4: host nplooj ntawv saum tus server.
Txuag tsim cov nplooj ntawv php nrog lub npe thiab php txuas ntxiv koj xav tau thiab upload nws rau tus neeg rau zaub mov rau koj lub xaib.
Yog lawm, qhov no yog nplooj ntawv "liab qab", koj yuav tsum tau tsim nws zoo ib yam li lwm nplooj ntawv ntawm koj lub xaib. Los yog nqa cov ntsiab lus ntawm nplooj ntawv no thiab ntxiv rau lawv mus rau ib nplooj ntawv uas twb muaj lawm ntawm lub xaib.