@@ -62,15 +62,38 @@ public function get_index(\Box_App $app)
6262 // Validate form data
6363 if ($ name && $ email && $ message ) {
6464 // Define sender and recipient
65+ $ parts = explode ('. ' , $ domain );
66+ $ sld = '' ;
67+ $ tld = '' ;
68+
69+ if (count ($ parts ) >= 3 ) {
70+ $ tld = implode ('. ' , array_slice ($ parts , -2 ));
71+ $ sld = $ parts [count ($ parts ) - 3 ];
72+ } elseif (count ($ parts ) === 2 ) {
73+ $ sld = $ parts [0 ];
74+ $ tld = $ parts [1 ];
75+ } else {
76+ $ error = "Error: Invalid domain format. " ;
77+ }
78+
79+ if ($ sld && $ tld ) {
80+ $ contact = $ this ->di ['db ' ]->getRow (
81+ 'SELECT * FROM service_domain WHERE sld = :sld AND tld = :tld ' ,
82+ ['sld ' => $ sld , 'tld ' => '. ' . $ tld ]
83+ );
84+ } else {
85+ $ error = "Error: Unable to extract SLD and TLD from the domain. " ;
86+ }
87+
6588 $ sender = [
6689 'email ' => $ email ,
6790 'name ' => $ name ,
6891 ];
6992 $ recipient = [
70- 'email ' => ' registrant@example.com ' , // Replace with actual registrant's email
71- 'name ' => ' Domain Registrant ' ,
93+ 'email ' => $ contact [ ' contact_email ' ],
94+ 'name ' => $ contact [ ' contact_first_name ' ] . ' ' . $ contact [ ' contact_last_name ' ] ,
7295 ];
73-
96+
7497 // Get email settings
7598 $ mod = $ this ->di ['mod ' ]('email ' );
7699 $ settings = $ mod ->getConfig ();
@@ -87,7 +110,7 @@ public function get_index(\Box_App $app)
87110 // Log activity if enabled
88111 if ($ logEnabled ) {
89112 $ activityService = $ this ->di ['mod_service ' ]('activity ' );
90- $ activityService ->logEmail ("Contact Domain Registrant: " . $ domain , null , $ email , ' registrant@example.com ' , $ message );
113+ $ activityService ->logEmail ("Contact Domain Registrant: " . $ domain , null , $ email , $ contact [ ' contact_email ' ] , $ message );
91114 }
92115 $ success = 'Your message has been sent successfully. ' ;
93116 } catch (\Exception $ e ) {
0 commit comments