File tree Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Expand file tree Collapse file tree 2 files changed +67
-0
lines changed Original file line number Diff line number Diff line change
1
+ <!DOCTYPE html>
2
+ <!-- =================Script written by DProvat.===================== -->
3
+ <!-- Please contact us if there are any errors or problems with usage. https://arprovat.com/ -->
4
+ < html lang ="en ">
5
+ < head >
6
+ < meta charset ="UTF-8 ">
7
+ < meta name ="viewport " content ="width=device-width, initial-scale=1.0 ">
8
+ < title > PHP function setup with ajax</ title >
9
+ < script src ="https://code.jquery.com/jquery-3.6.0.min.js "> </ script >
10
+
11
+ </ head >
12
+ < body >
13
+
14
+ < form id ="emailForm ">
15
+ < label for ="email "> Email:</ label > < br >
16
+ < input type ="email " id ="email " name ="email "> < br >
17
+ < button type ="button " id ="submitBtn "> Submit</ button >
18
+ </ form >
19
+
20
+ < script >
21
+ $ ( document ) . ready ( function ( ) {
22
+ $ ( "#submitBtn" ) . click ( function ( ) {
23
+ var email = $ ( "#email" ) . val ( ) ;
24
+ $ ( this ) . prop ( 'disabled' , true ) . text ( 'Sending...' ) ;
25
+ $ . ajax ( {
26
+ type : "POST" ,
27
+ url : "server.php" ,
28
+ data : { email : email } ,
29
+ success : function ( response ) {
30
+ alert ( response ) ;
31
+ $ ( "#submitBtn" ) . prop ( 'disabled' , false ) . text ( 'Submit' ) ;
32
+ }
33
+ } ) ;
34
+ } ) ;
35
+ } ) ;
36
+ </ script >
37
+ </ body >
38
+ </ html >
Original file line number Diff line number Diff line change
1
+ <?php
2
+ // Script written by DProvat.
3
+ // Please contact us if there are any errors or problems with usage. https://arprovat.com/
4
+
5
+ if (isset ($ _POST ['email ' ])) {
6
+ $ email = $ _POST ['email ' ];
7
+
8
+ // $adminsEmail= '[email protected] '; //replace your admin mail where sent
9
+
10
+ $ adminsEmail = 'your@mail ' ; //replace your admin mail where sent
11
+ $ to = $ email ;
12
+ $ subject = 'php mail function testing ' ;
13
+
14
+ $ headers = "From: " .$ adminsEmail ."\r\n" ;
15
+ $ headers .= "Reply-To: " .$ email ."\r\n" ;
16
+ $ headers .= "MIME-Version: 1.0 \r\n" ;
17
+ $ headers .= "Content-Type: text/html; charset=ISO-8859-1 \r\n" ;
18
+
19
+ $ body = "mail body. you can replace it with HTML " ;
20
+
21
+ if (mail ($ to , $ subject , $ body , $ headers )) {
22
+ echo 'mail sent successfully ' ;
23
+ exit ();
24
+ }else {
25
+ echo 'something error ' ;
26
+ }
27
+ }else {
28
+ echo 'mail not found ' ;
29
+ }
You can’t perform that action at this time.
0 commit comments