Download as pdf or txt
Download as pdf or txt
You are on page 1of 7

SENDING E-MAIL

YouT PHP SCTipts can send emal as wal. to enabe


emal, edft this:_ectton in the PHP in41altzatfon fRle

To send mil, you use the mäd funtfon

mdiu (toiy Subct, message'l, addttonal keaders [ addt Honal-


panametesJ]>|
ths Sends máil do the eml2address In to,

with sbkct suhhut and message message. You can also


Set additHonal mal eaders and panamerer%, to

Sendmdil.

Prcgvarn:

hdml7 : i i t ) soi2-
chead <4RtHe7 Send email 41itte <1head7

body7
4hl7 Send emil <lhiz
br7
foTm method "post" acifon =
"phpemail. php7
Please type you Comments and, cltek suonmit :

ba7
entaLa name 50" Nws = "s'Y<ltextMea 7
:
"message" Cets

Abar
Input type = "Submtt"
value -"Submit">

2 body7
21htmd
Output:

@phpemal- ktml
Send ema
please type yo Commevts and. etk subnl+:

NMce page you haye got

Submlt

phpemail.php
htmz
4heady 4HHe7 Your emal was sent <Hte7 <Iheadz

<body7
h7 Youy ema uwas Sent)hlz
Thanks Ror youn emal.
ba7

2php i t
mail"steve @fspname.com",webmad 4REQUEST I"messa "1)5

2Ioody7
chtml7
Output ,

@phpemai.php
Your email was gent
Thanks bi youn email.
SENDING ADVANCED E.má

Yo Can also Send emil with additonal

headers Such as a cc headen and a bec headen.

Phpadvemail. html

4html7
head HHe7 Send. amail with headens <ittey 21head

body7
hI7 send em with headers <lhtz
foTm method "post" actfon » "phpadvemau php 7

please kype Yeuwn ommerts and, elkek Submit

ce: Enput *ype =Hent name 'Ccz

bec:input *ype "tent" name "bee ">


Lbn7
's">z}textaua
tent aa name = "message" cols 'so' a0ws-

Aba7

sinput yPe Subnat valse "subml4"7

om7
41body7
lhtml
Output

phpadvemall. ht mlL

Send emdl uath headans


Comments andl clfek Subit :
Please *ype youn
CCed@tsphame.com
bcetéd@tsphame.com
well page you have 9ot

Submit

Phpadvemdd.php
Ahtml7
emad Was sent 1tHey <lheady
Lhead 4ittez Your

body7
was sent <Ihiz
Zh7 your emal
uith headers.
Thanks for youT emdi

bnz

49php
headers
A(fsset C$-REQUEST [ 'ee "I))
$headers. "ce: ".". 4RequEST [ e"]. "l«\»"s

4Ctsset C_REQuEST [ "bec"J))

headers. "bec .
4REQUESTC"bee"] . "1r\n";

Sresut mall("teve@lspname.dom"we Ml
$RE6UEST I "message "J , $headuns)

97
41body7 A]html7
utput:

phpadvemál.php
Ybuun enmal was sedt

Thanks fov yo email uwth headuns,

ADDING ATTACHMENTS To E-Mall

oL can also Send attachments uth youn

additonal
emdil from PHP, although that takes Some

woTk

Example
htaml
head7 4HHe7 Sending emu ith atachments e
fhend
&bady7
h7 Sendtng ema cuith atachmerts
<1N7
2php
$to steve @fspname Com 3

GCubct web m "3

Smessage "This eml has an attachment. "

attachment"mage. Jpg"s
$atochnent- MiME type "mag |Jpeä "st
$handle fopen C^attachment, "nb")
=

Soata fvead Chande


fmestze ,
C4atachmert) 3
fctose C^handle)s

ounday Mulktpant.eounda ")


Sheades MiME-Veson : \6\n|

Cotent-Type : mutpant Iwead; \n


"
"boundany -\" ". Ahaunday. "\ "

Gdata, =
Chunk-Split (base b4- encade $data) )
tert -- ".boundary. "\n.

Content-TYpe teut platn\n Contert-Transfen -Bneodin9 :7blE»

message. "Inln--' . Sbounda. "\n'.

Content-TYpe" . 4atachrnent-MimE.type .'; {n hame =\

atochment. "\"n dotent -Tvansfen-Encodtng 1kose 64 \»\n.


data. \nin-- " . $boundas. "--\n" 3

4nesult - @mail C4to, ^subct Ateut, $headers);

i CAresul)
R
echo he emdl wuas sent

else

echo The email was not Sent

27
<lbody 2Ihtml7
Output:

phpematlatlachmonts. php
Sending emal uth attachments

Your emal evas Sent.

You might also like