File: /var/www/html/WPYadBatya/wp-content/themes/yad-batya/functions.php
<?php
function enqueue_ajax_form_script() {
wp_enqueue_script('form-handler', get_template_directory_uri() . '/js/custom.js', array('jquery'), null, true);
wp_localize_script('form-handler', 'ajaxurl', admin_url('admin-ajax.php'));
}
add_action('wp_enqueue_scripts', 'enqueue_ajax_form_script');
function send_form_email() {
parse_str($_POST['form_data'], $form_data);
$fname = sanitize_text_field($form_data['fname']);
$lname = sanitize_text_field($form_data['lname']);
$name = $fname.' '.$lname;
$email = sanitize_email($form_data['email']);
$phone = sanitize_text_field($form_data['phone']);
$location = sanitize_text_field($form_data['location']);
$area = sanitize_text_field($form_data['volunteer_area']);
$subject = sanitize_text_field($form_data['subject']);
$message = sanitize_textarea_field($form_data['message']);
$admin_email = get_option('admin_email');
$headers = array('Content-Type: text/plain; charset=UTF-8');
$headers = array(
'Content-Type: text/html; charset=utf-8'
);
$email_subject = "Volunteer Form Submission: $subject";
$email_message = "<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>
<head>
<meta charset='utf-8'> <!-- utf-8 works for most cases -->
<meta name='viewport' content='width=device-width'> <!-- Forcing initial-scale shouldn't be necessary -->
<meta http-equiv='X-UA-Compatible' content='IE=edge'> <!-- Use the latest (edge) version of IE rendering engine -->
<meta name='x-apple-disable-message-reformatting'> <!-- Disable auto-scale in iOS 10 Mail entirely -->
<meta name='format-detection' content='telephone=no,address=no,email=no,date=no,url=no'> <!-- Tell iOS not to automatically link certain text strings. -->
<meta name='color-scheme' content='light'>
<meta name='supported-color-schemes' content='light'>
<title>Welcome</title> <!-- The title tag shows in email notifications, like Android 4.4. -->
<!-- What it does: Makes background images in 72ppi Outlook render at correct size. -->
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!-- Web Font / @font-face : BEGIN -->
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap' rel='stylesheet'>
<!-- All other clients get the webfont reference; some will render the font and others will silently fail to the fallbacks. More on that here: http://stylecampaign.com/blog/2015/02/webfont-support-in-email/ -->
<!--[if !mso]>
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap' rel='stylesheet'>
<![endif]-->
<!-- Desktop Outlook chokes on web font references and defaults to Times New Roman, so we force a safe fallback font. -->
<!--[if mso]>
<style>
*, body,div,p,a ,h1,h2,h3,h4,h5,h6, table, td, th {
font-family: 'Poppins', sans-serif;
}
</style>
<![endif]-->
<!-- Web Font / @font-face : END -->
<!-- CSS Reset : BEGIN -->
<style>
:root {
color-scheme: light;
supported-color-schemes: light;
}
html,
body {
margin: 0 auto !important;
padding: 0 !important;
height: 100% !important;
width: 100% !important;
}
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
/* What it does: Centers email on Android 4.4 */
div[style*='margin: 16px 0'] {
margin: 0 !important;
}
/* What it does: forces Samsung Android mail clients to use the entire viewport */
#MessageViewBody, #MessageWebViewDiv{
width: 100% !important;
}
/* What it does: Stops Outlook from adding extra spacing to tables. */
table,
td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
/* What it does: Fixes webkit padding issue. */
table {
border-spacing: 0 !important;
border-collapse: collapse !important;
table-layout: fixed !important;
margin: 0 auto !important;
}
/* What it does: Uses a better rendering method when resizing images in IE. */
img {
-ms-interpolation-mode:bicubic;
}
/* What it does: Prevents Windows 10 Mail from underlining links despite inline CSS. Styles for underlined links should be inline. */
a {
text-decoration: none;
}
/* What it does: A work-around for email clients meddling in triggered links. */
a[x-apple-data-detectors], /* iOS */
.unstyle-auto-detected-links a,
.aBn {
border-bottom: 0 !important;
cursor: default !important;
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
/* What it does: Prevents Gmail from changing the text color in conversation threads. */
.im {
color: inherit !important;
}
/* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */
.a6S {
display: none !important;
opacity: 0.01 !important;
}
/* If the above doesn't work, add a .g-img class to any image in question. */
img.g-img + div {
display: none !important;
}
/* What it does: Removes right gutter in Gmail iOS app: https://github.com/TedGoas/Cerberus/issues/89 */
/* Create one of these media queries for each additional viewport size you'd like to fix */
/* iPhone 4, 4S, 5, 5S, 5C, and 5SE */
@media only screen and (min-device-width: 320px) and (max-device-width: 374px) {
u ~ div .email-container {
min-width: 320px !important;
}
}
/* iPhone 6, 6S, 7, 8, and X */
@media only screen and (min-device-width: 375px) and (max-device-width: 413px) {
u ~ div .email-container {
min-width: 375px !important;
}
}
/* iPhone 6+, 7+, and 8+ */
@media only screen and (min-device-width: 414px) {
u ~ div .email-container {
min-width: 414px !important;
}
}
</style>
<!-- CSS Reset : END -->
<!-- Progressive Enhancements : BEGIN -->
<style>
@media screen and (max-width: 579px) {
.name-block{
width: 100% !important;
margin-left: 0 !important;
}
.inner-td{
padding: 20px !important;
}
}
/* Media Queries */
@media screen and (max-width: 480px) {
/* What it does: Forces table cells into full-width rows. */
.stack-column,
.stack-column-center {
display: block !important;
width: 100% !important;
max-width: 100% !important;
direction: ltr !important;
}
/* And center justify these ones. */
.stack-column-center {
text-align: center !important;
}
/* What it does: Generic utility class for centering. Useful for images, buttons, and nested tables. */
.center-on-narrow {
text-align: center !important;
display: block !important;
margin-left: auto !important;
margin-right: auto !important;
float: none !important;
}
table.center-on-narrow {
display: inline-block !important;
}
/* What it does: Adjust typography on small screens to improve readability */
}
</style>
<!-- Progressive Enhancements : END -->
<!-- MSO dark mode fix : use the class name for texts to remain in white -->
<!--[if mso ]>
<style>
a{
line-height: normal !important;
text-decoration: none !important;
}
.ms-whiteX {
mso-style-textfill-type:gradient;
mso-style-textfill-fill-gradientfill-stoplist:'0 \#FFFFFF 0 100000\,100000 \#FFFFFF 0 100000';
}
</style>
<![endif]-->
</head>
<!--
The email background color (#ECF3FE) is defined in three places:
1. body tag: for most email clients
2. center tag: for Gmail and Inbox mobile apps and web versions of Gmail, GSuite, Inbox, Yahoo, AOL, Libero, Comcast, freenet, Mail.ru, Orange.fr
3. mso conditional: For Windows 10 Mail
-->
<body width='100%' style='margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #fff;'>
<center role='article' aria-roledescription='email' lang='en' style='width: 100%; background-color: #fff;'>
<!--[if mso | IE]>
<table role='presentation' border='0' cellpadding='0' cellspacing='0' width='100%' style='background-color: #ECF3FE;'>
<tr>
<td>
<![endif]-->
<!-- Create white space after the desired preview text so email clients don’t pull other distracting text into the inbox preview. Extend as necessary. -->
<!-- Preview Text Spacing Hack : BEGIN -->
<div style='display: none; font-size: 1px; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: 'Prompt', sans-serif;'>
‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
</div>
<!-- Preview Text Spacing Hack : END -->
<!--
Set the email width. Defined in two places:
1. max-width for all clients except Desktop Windows Outlook, allowing the email to squish on narrow but never go wider than 680px.
2. MSO tags for Desktop Windows Outlook enforce a 680px width.
Note: The Fluid and Responsive templates have a different width (600px). The hybrid grid is more 'fragile', and I've found that 680px is a good width. Change with caution.
-->
<div style='background-color: #975FA9; max-width: 800px; margin: 0 auto;font-family: 'Poppins', sans-serif; padding: 15px;' class='email-container'>
<!--[if mso]>
<table align='center' role='presentation' cellspacing='0' cellpadding='0' border='0' width='800'>
<tr>
<td>
<![endif]-->
<!-- Email Body : BEGIN -->
<table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' style='width: 780px; margin: 0px auto 0 !important; font-family: 'Poppins', sans-serif; max-width: 100%;'>
<tr>
<td>
<table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' width='100%' style='margin: auto !important; '>
<!-- Clear Spacer : BEGIN -->
<!-- <tr>
<td aria-hidden='true' height='10' style='font-size: 0px; line-height: 0px;'>
</td>
</tr> -->
<!-- Clear Spacer : END -->
<tr>
<td class='inner-td' style='background: #fff; padding: 40px; border-top: solid 5px #975FA9; margin-bottom: 20px;'>
<div style='padding: 0px 0px 10px; text-align: center; border-bottom:1px solid #ededed; padding: 0px 0px 10px; margin-bottom: 20px;'>
<img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/email-logo.png' width='' height='56' alt='alt_text' border='0' >
</div>
<h4 style='font-family: 'Poppins', sans-serif; color: #292D32; font-size: 20px; font-weight: 600; margin: 0; margin-bottom: 15px;'>Hi ".$name.",</h4>
<div style='display:block; text-align: center; padding-top: 15px;'>
<img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/contact.png' alt=''>
</div>
<div style='display:block; box-sizing: border-box; width: 100%;'>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #292D32; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Name</span>: ".$name."
</p>
</div>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Email</span>: ".$email."
</p>
</div>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Phone</span>: ".$phone."
</p>
</div>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Location</span>: ".$location."
</p>
</div>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Area</span>: ".$area."
</p>
</div>
<div class='name-block' style='margin-bottom: 20px; display:block; width: 100%; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0;'>
<span style='font-weight: 500;'>Subject</span>: ".$subject."
</p>
</div>
<div style='display:inline-block; box-sizing: border-box;'>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0 0 10px;'>
<span style='font-weight: 500;'>Message</span>
</p>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 13px; margin: 0 0 15px;'>
".$message."
</p>
<p style='margin-top: 30px; margin-bottom: 5px; font-family: 'Poppins', sans-serif; color: #292D32; font-size: 12px;'>Thank you</p>
<h4 style='font-size: 12px; margin-top: 0; color: #292D32; font-weight: 700;'>Team Yad Batya</h4>
</div>
</div>
</td>
</tr>
<!-- Clear Spacer : BEGIN -->
<!-- Clear Spacer : END -->
</table>
</td>
</tr>
</table>
<!-- Email Body : END -->
<!-- Email Social Media : BEGIN -->
<tr>
<td>
<!-- <table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' width='100%'>
<tr>
<td style='text-align: center; padding: 15px;'>
<p style='font-family: 'Poppins', sans-serif; text-align: center; margin: 0;'>
<a href='#' style='display: inline-block; margin: 0 2px;'><img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/upwrk.png' alt='Up work'></a>
<a href='#' style='display: inline-block; margin: 0 2px;'><img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/linkd.png' alt='Linked in'></a>
</p>
</td>
</tr>
</table> -->
</td>
</tr>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</div>
<!-- Full Bleed Background Section : BEGIN -->
<!-- Full Bleed Background Section : END -->
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</center>
</body>
</html>";
if (wp_mail($admin_email, $email_subject, $email_message, $headers)) {
wp_send_json_success("Thank you for contacting us!");
} else {
wp_send_json_error("There was an issue sending your message. Please try again.");
}
}
add_action('wp_ajax_send_form_email', 'send_form_email');
add_action('wp_ajax_nopriv_send_form_email', 'send_form_email');
function handle_subscribe_request() {
// Make sure email is provided
if (isset($_POST['email']) && is_email($_POST['email'])) {
$email = sanitize_email($_POST['email']);
// Add email to your database or email list (e.g., MailChimp, custom database)
// Here we just simulate the action by sending a confirmation email.
// For demonstration, we're sending an email to the admin
$admin_email = get_option('admin_email');
$subject = "New Subscriber";
// $message = "A new subscriber has joined with email: $email.";
$message = "<!DOCTYPE html>
<html lang='en' xmlns='http://www.w3.org/1999/xhtml' xmlns:v='urn:schemas-microsoft-com:vml' xmlns:o='urn:schemas-microsoft-com:office:office'>
<head>
<meta charset='utf-8'> <!-- utf-8 works for most cases -->
<meta name='viewport' content='width=device-width'> <!-- Forcing initial-scale shouldn't be necessary -->
<meta http-equiv='X-UA-Compatible' content='IE=edge'> <!-- Use the latest (edge) version of IE rendering engine -->
<meta name='x-apple-disable-message-reformatting'> <!-- Disable auto-scale in iOS 10 Mail entirely -->
<meta name='format-detection' content='telephone=no,address=no,email=no,date=no,url=no'> <!-- Tell iOS not to automatically link certain text strings. -->
<meta name='color-scheme' content='light'>
<meta name='supported-color-schemes' content='light'>
<title>Welcome</title> <!-- The title tag shows in email notifications, like Android 4.4. -->
<!-- What it does: Makes background images in 72ppi Outlook render at correct size. -->
<!--[if gte mso 9]>
<xml>
<o:OfficeDocumentSettings>
<o:AllowPNG/>
<o:PixelsPerInch>96</o:PixelsPerInch>
</o:OfficeDocumentSettings>
</xml>
<![endif]-->
<!-- Web Font / @font-face : BEGIN -->
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap' rel='stylesheet'>
<!-- All other clients get the webfont reference; some will render the font and others will silently fail to the fallbacks. More on that here: http://stylecampaign.com/blog/2015/02/webfont-support-in-email/ -->
<!--[if !mso]>
<link href='https://fonts.googleapis.com/css2?family=Poppins:wght@300;400;500;600;700&display=swap' rel='stylesheet'>
<![endif]-->
<!-- Desktop Outlook chokes on web font references and defaults to Times New Roman, so we force a safe fallback font. -->
<!--[if mso]>
<style>
*, body,div,p,a ,h1,h2,h3,h4,h5,h6, table, td, th {
font-family: 'Poppins', sans-serif;
}
</style>
<![endif]-->
<!-- Web Font / @font-face : END -->
<!-- CSS Reset : BEGIN -->
<style>
:root {
color-scheme: light;
supported-color-schemes: light;
}
html,
body {
margin: 0 auto !important;
padding: 0 !important;
height: 100% !important;
width: 100% !important;
}
* {
-ms-text-size-adjust: 100%;
-webkit-text-size-adjust: 100%;
}
/* What it does: Centers email on Android 4.4 */
div[style*='margin: 16px 0'] {
margin: 0 !important;
}
/* What it does: forces Samsung Android mail clients to use the entire viewport */
#MessageViewBody, #MessageWebViewDiv{
width: 100% !important;
}
/* What it does: Stops Outlook from adding extra spacing to tables. */
table,
td {
mso-table-lspace: 0pt !important;
mso-table-rspace: 0pt !important;
}
/* What it does: Fixes webkit padding issue. */
table {
border-spacing: 0 !important;
border-collapse: collapse !important;
table-layout: fixed !important;
margin: 0 auto !important;
}
/* What it does: Uses a better rendering method when resizing images in IE. */
img {
-ms-interpolation-mode:bicubic;
}
/* What it does: Prevents Windows 10 Mail from underlining links despite inline CSS. Styles for underlined links should be inline. */
a {
text-decoration: none;
}
/* What it does: A work-around for email clients meddling in triggered links. */
a[x-apple-data-detectors], /* iOS */
.unstyle-auto-detected-links a,
.aBn {
border-bottom: 0 !important;
cursor: default !important;
color: inherit !important;
text-decoration: none !important;
font-size: inherit !important;
font-family: inherit !important;
font-weight: inherit !important;
line-height: inherit !important;
}
/* What it does: Prevents Gmail from changing the text color in conversation threads. */
.im {
color: inherit !important;
}
/* What it does: Prevents Gmail from displaying a download button on large, non-linked images. */
.a6S {
display: none !important;
opacity: 0.01 !important;
}
/* If the above doesn't work, add a .g-img class to any image in question. */
img.g-img + div {
display: none !important;
}
/* What it does: Removes right gutter in Gmail iOS app: https://github.com/TedGoas/Cerberus/issues/89 */
/* Create one of these media queries for each additional viewport size you'd like to fix */
/* iPhone 4, 4S, 5, 5S, 5C, and 5SE */
@media only screen and (min-device-width: 320px) and (max-device-width: 374px) {
u ~ div .email-container {
min-width: 320px !important;
}
}
/* iPhone 6, 6S, 7, 8, and X */
@media only screen and (min-device-width: 375px) and (max-device-width: 413px) {
u ~ div .email-container {
min-width: 375px !important;
}
}
/* iPhone 6+, 7+, and 8+ */
@media only screen and (min-device-width: 414px) {
u ~ div .email-container {
min-width: 414px !important;
}
}
</style>
<!-- CSS Reset : END -->
<!-- Progressive Enhancements : BEGIN -->
<style>
@media screen and (max-width: 579px) {
.name-block{
width: 100% !important;
margin-left: 0 !important;
}
.inner-td{
padding: 20px !important;
}
}
/* Media Queries */
@media screen and (max-width: 480px) {
/* What it does: Forces table cells into full-width rows. */
.stack-column,
.stack-column-center {
display: block !important;
width: 100% !important;
max-width: 100% !important;
direction: ltr !important;
}
/* And center justify these ones. */
.stack-column-center {
text-align: center !important;
}
/* What it does: Generic utility class for centering. Useful for images, buttons, and nested tables. */
.center-on-narrow {
text-align: center !important;
display: block !important;
margin-left: auto !important;
margin-right: auto !important;
float: none !important;
}
table.center-on-narrow {
display: inline-block !important;
}
/* What it does: Adjust typography on small screens to improve readability */
}
</style>
<!-- Progressive Enhancements : END -->
<!-- MSO dark mode fix : use the class name for texts to remain in white -->
<!--[if mso ]>
<style>
a{
line-height: normal !important;
text-decoration: none !important;
}
.ms-whiteX {
mso-style-textfill-type:gradient;
mso-style-textfill-fill-gradientfill-stoplist:'0 \#FFFFFF 0 100000\,100000 \#FFFFFF 0 100000';
}
</style>
<![endif]-->
</head>
<!--
The email background color (#ECF3FE) is defined in three places:
1. body tag: for most email clients
2. center tag: for Gmail and Inbox mobile apps and web versions of Gmail, GSuite, Inbox, Yahoo, AOL, Libero, Comcast, freenet, Mail.ru, Orange.fr
3. mso conditional: For Windows 10 Mail
-->
<body width='100%' style='margin: 0; padding: 0 !important; mso-line-height-rule: exactly; background-color: #fff;'>
<center role='article' aria-roledescription='email' lang='en' style='width: 100%; background-color: #fff;'>
<!--[if mso | IE]>
<table role='presentation' border='0' cellpadding='0' cellspacing='0' width='100%' style='background-color: #ECF3FE;'>
<tr>
<td>
<![endif]-->
<!-- Create white space after the desired preview text so email clients don’t pull other distracting text into the inbox preview. Extend as necessary. -->
<!-- Preview Text Spacing Hack : BEGIN -->
<div style='display: none; font-size: 1px; line-height: 1px; max-height: 0px; max-width: 0px; opacity: 0; overflow: hidden; mso-hide: all; font-family: 'Prompt', sans-serif;'>
‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌ ‌
</div>
<!-- Preview Text Spacing Hack : END -->
<!--
Set the email width. Defined in two places:
1. max-width for all clients except Desktop Windows Outlook, allowing the email to squish on narrow but never go wider than 680px.
2. MSO tags for Desktop Windows Outlook enforce a 680px width.
Note: The Fluid and Responsive templates have a different width (600px). The hybrid grid is more 'fragile', and I've found that 680px is a good width. Change with caution.
-->
<div style='background-color: #975FA9; max-width: 800px; margin: 0 auto;font-family: 'Poppins', sans-serif; padding: 15px;' class='email-container'>
<!--[if mso]>
<table align='center' role='presentation' cellspacing='0' cellpadding='0' border='0' width='800'>
<tr>
<td>
<![endif]-->
<!-- Email Body : BEGIN -->
<table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' style='width: 780px; margin: 0px auto 0 !important; font-family: 'Poppins', sans-serif; max-width: 100%;'>
<tr>
<td>
<table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' width='100%' style='margin: auto !important; '>
<!-- Clear Spacer : BEGIN -->
<!-- <tr>
<td aria-hidden='true' height='10' style='font-size: 0px; line-height: 0px;'>
</td>
</tr> -->
<!-- Clear Spacer : END -->
<tr>
<td class='inner-td' style='background: #fff; padding: 40px; border-top: solid 5px #975FA9; margin-bottom: 20px;'>
<div style='padding: 0px 0px 10px; text-align: center; border-bottom:1px solid #ededed; padding: 0px 0px 10px; margin-bottom: 20px;'>
<img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/email-logo.png' width='' height='56' alt='alt_text' border='0' >
</div>
<h4 style='font-family: 'Poppins', sans-serif; color: #292D32; font-size: 20px; font-weight: 600; margin: 0; margin-bottom: 15px;'>Hi ".$name.",</h4>
<div style='display:block; text-align: center; padding-top: 15px;'>
<img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/contact.png' alt=''>
</div>
<p style='font-family: 'Poppins', sans-serif; color: #697F9B; font-size: 14px; margin-top: 30px; margin-bottom: 30px;'>We wanted to inform you that a user has recently made a message on your platform.</p>
<div style='display:block; box-sizing: border-box; width: 100%;'>
<div style='display:inline-block; box-sizing: border-box;'>
<h2>Thank you for subscribing to our newsletter!</h2>
<p>We appreciate your interest and will keep you updated with the latest news and updates.</p>
<p><small>If you did not subscribe to this newsletter, please disregard this email.</small></p>
<p style='margin-top: 30px; margin-bottom: 5px; font-family: 'Poppins', sans-serif; color: #292D32; font-size: 12px;'>Thank you</p>
<h4 style='font-size: 12px; margin-top: 0; color: #292D32; font-weight: 700;'>Team Yad Batya</h4>
</div>
</div>
</td>
</tr>
<!-- Clear Spacer : BEGIN -->
<!-- Clear Spacer : END -->
</table>
</td>
</tr>
</table>
<!-- Email Body : END -->
<!-- Email Social Media : BEGIN -->
<tr>
<td>
<!-- <table role='presentation' cellspacing='0' cellpadding='0' border='0' bgcolor='' width='100%'>
<tr>
<td style='text-align: center; padding: 15px;'>
<p style='font-family: 'Poppins', sans-serif; text-align: center; margin: 0;'>
<a href='#' style='display: inline-block; margin: 0 2px;'><img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/upwrk.png' alt='Up work'></a>
<a href='#' style='display: inline-block; margin: 0 2px;'><img src='https://yadbatya.spericorn.com/wp-content/themes/yad-batya/img/linkd.png' alt='Linked in'></a>
</p>
</td>
</tr>
</table> -->
</td>
</tr>
<!--[if mso]>
</td>
</tr>
</table>
<![endif]-->
</div>
<!-- Full Bleed Background Section : BEGIN -->
<!-- Full Bleed Background Section : END -->
<!--[if mso | IE]>
</td>
</tr>
</table>
<![endif]-->
</center>
</body>
</html>";
$headers = array(
'Content-Type: text/html; charset=utf-8'
);
if (wp_mail($admin_email, $subject, $message, $headers)) {
wp_send_json_success('Thank you for subscribing!');
} else {
wp_send_json_error('There was an issue with the subscription. Please try again later.');
}
} else {
wp_send_json_error('Please provide a valid email address.');
}
}
add_action('wp_ajax_subscribe_newsletter', 'handle_subscribe_request');
add_action('wp_ajax_nopriv_subscribe_newsletter', 'handle_subscribe_request');
//---------------------------------------------------------------------------------------------------------------------------
function process_donation() {
if (isset($_POST['form_data'])) {
$form_data = $_POST['form_data'];
}
$donationData = [];
$transactionResponse = null;
$amount =str_replace(',', '', $form_data['donation_total']);
// Capture the client IP adress
// $form_data['ip_address'] = $_SERVER['REMOTE_ADDR'];
// if (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
// $form_data['ip_address'] = explode(',', $_SERVER['HTTP_X_FORWARDED_FOR'])[0]; // Use the first IP if behind a proxy
// }
// Process with Authorize.Net
if ($form_data['donation_frequency'] === 'once') {
$transactionResponse = authorizenetChargeCreditCard($amount,$form_data);
} elseif ($form_data['donation_frequency'] === 'monthly') {
$chargeResponse = authorizenetChargeCreditCard($amount,$form_data); // Charge immediately
if ($chargeResponse['success']) {
$startDate = new DateTime("now");
$intervalType = $form_data['donation_frequency']; // 'monthly' or 'annually'
if ($form_data['donation_frequency'] === 'monthly') {
$startDate->modify("+1 month");
}
// else if ($form_data['donation_frequency'] === 'annually') {
// $startDate->modify("+1 year");
// }
$subscriptionResponse = authorizenetCreateSubscription($amount, $startDate, $intervalType,$form_data);
$transactionResponse = $subscriptionResponse;
} else {
$transactionResponse = $chargeResponse;
}
}
// Check response and return success or error
if ($transactionResponse && $transactionResponse['success']) {
wp_send_json_success($transactionResponse['data']);
} else {
wp_send_json_error(isset($transactionResponse['data']) ? $transactionResponse['data'] : ['message' => 'An error occurred.']);
}
wp_die(); // End the function to return a proper response
}
add_action('wp_ajax_process_donation', 'process_donation');
add_action('wp_ajax_nopriv_process_donation', 'process_donation');
require_once ABSPATH.'/vendor/autoload.php';
use net\authorize\api\contract\v1 as AnetAPI;
use net\authorize\api\controller as AnetController;
function authorizenetChargeCreditCard($amount,$form_data) {
error_log('Form Data: ' . print_r($form_data, true));
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
// $merchantAuthentication->setName(get_option('authorizenet_app_login_id_test', true));
// $merchantAuthentication->setTransactionKey(get_option('authorizenet_transaction_key_test', true));
$merchantAuthentication->setName(get_option('authorizenet_app_login_id', true));
$merchantAuthentication->setTransactionKey(get_option('authorizenet_transaction_key', true));
$cardNumber = sanitize_text_field($form_data['card_number']);
$month = sanitize_text_field($form_data['month']);
$year = sanitize_text_field($form_data['year']);
$lastyear = substr($year, -2);
$expDateInput = $month.'/'.$lastyear;//sanitize_text_field($form_data['exp_date']);
$donorEmail = 'admin@gmail.com';//sanitize_email($form_data['donor_email']);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($cardNumber);
// Create a DateTime object from the date input
$expDate = DateTime::createFromFormat('m/y', $expDateInput);
// Format the date to 'YYYY-MM'
$expDateFormatted = $expDate ? $expDate->format('Y-m') : '';
// Set the formatted expiration date to the credit card object
$creditCard->setExpirationDate($expDateFormatted);
// Add the payment data to a paymentType object
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create order information
$order = new AnetAPI\OrderType();
$order->setDescription("Yad Batya Donation");
// Set the customer's Bill To address
$customerAddress = new AnetAPI\CustomerAddressType();
$customerAddress->setFirstName($form_data['donor_fname']);
$customerAddress->setLastName($form_data['donor_lname']);
$customerAddress->setAddress($form_data['donor_address']);
$customerAddress->setCity($form_data['donor_city']);
$customerAddress->setState($form_data['donor_state']);
$customerAddress->setState($form_data['zip']);
// $customerAddress->setPhoneNumber($form_data['donor_phone']);
// Set the customer's identifying information
$customerData = new AnetAPI\CustomerDataType();
$customerData->setEmail($donorEmail);
// Create a transaction
$transactionRequestType = new AnetAPI\TransactionRequestType();
$transactionRequestType->setTransactionType("authCaptureTransaction");
$transactionRequestType->setAmount($amount);
$transactionRequestType->setPayment($paymentOne);
$transactionRequestType->setBillTo($customerAddress);
$transactionRequestType->setCustomer($customerData);
// $transactionRequestType->setCustomerIP($form_data['ip_address']);
// Create and send request
$request = new AnetAPI\CreateTransactionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setTransactionRequest($transactionRequestType);
$controller = new AnetController\CreateTransactionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
// $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
// Initialize structured response
$transactionResponseData = [
'success' => false,
'data' => [
'transactionStatus' => 'error',
'message' => 'Transaction failed with no response.',
'authCode' => null,
'transId' => null,
'errorCode' => null,
'errorText' => null,
]
];
if ($response != null) {
$transactionResponse = $response->getTransactionResponse();
// Initialize email variables
// $recipient = "info@yadbatya.com";
$recipient = "annie@spericorn.com";
$subject = "Authorize.NET Transaction Declined";
$headers = ['Content-Type: text/html; charset=UTF-8'];
// Check if there are errors in the transaction response first
if ($transactionResponse != null && $transactionResponse->getErrors() != null) {
// Get the first error message
$error = $transactionResponse->getErrors()[0];
$errorCode = $error->getErrorCode();
$errorText = $error->getErrorText();
// Return a detailed error message from transaction response
$transactionResponseData['data'] = [
'transactionStatus' => 'error',
'message' => $errorText,
'errorCode' => $errorCode,
'errorText' => $errorText,
'authCode' => null,
'transId' => null,
];
// Log the error for debugging purposes
error_log("Authorize.NET Transaction Error: Code $errorCode, Message: $errorText");
}
// Fallback to general messages if no transaction response errors exist
else if ($response->getMessages() != null && $response->getMessages()->getResultCode() === "Error") {
// Get the first error message from the general response messages
$error = $response->getMessages()->getMessage()[0];
$errorCode = $error->getCode();
$errorText = $error->getText();
$transactionResponseData['data'] = [
'transactionStatus' => 'error',
'message' => $errorText,
'errorCode' => $errorCode,
'errorText' => $errorText,
'authCode' => null,
'transId' => null,
];
// Log the error for debugging purposes
error_log("Authorize.NET General Error: Code $errorCode, Message: $errorText");
}
// Handle successful or held transactions
else if ($transactionResponse != null) {
$responseCode = $transactionResponse->getResponseCode();
switch ($responseCode) {
case "1": // Approved
$transactionResponseData['success'] = true;
$transactionResponseData['data'] = [
'transactionStatus' => 'success',
'message' => 'This transaction has been approved.',
'authCode' => $transactionResponse->getAuthCode(),
'transId' => $transactionResponse->getTransId(),
];
break;
case "4": // Held for review
$transactionResponseData['success'] = true; // Or false based on your handling of held for review transactions
$transactionResponseData['data'] = [
'transactionStatus' => 'review',
'message' => 'This transaction has been held for review.',
'authCode' => $transactionResponse->getAuthCode(),
'transId' => $transactionResponse->getTransId(),
];
break;
default: // Unknown error
$message = $transactionResponse->getErrors() ? $transactionResponse->getErrors()[0]->getErrorText() : "An error occurred during processing. Please try again.";
$errorCode = $transactionResponse->getErrors() ? $transactionResponse->getErrors()[0]->getErrorCode() : $responseCode;
$transactionResponseData['data'] = [
'transactionStatus' => 'error',
'message' => $message,
'errorCode' => $errorCode,
'errorText' => $message,
'authCode' => null,
'transId' => null,
];
break;
}
}
else {
$transactionResponseData['data']['message'] = "Unhandled error occurred.";
}
} else {
// No response object was returned
$transactionResponseData['data']['message'] = 'Transaction failed with no response.';
}
return $transactionResponseData;
}
function authorizenetCreateSubscription($amount, DateTime $startDate, $intervalType,$form_data) {
// Initialize the structured response array
$subscriptionResponse = [
'success' => false,
'data' => [
'message' => 'Subscription creation failed with no response.',
'subscriptionId' => null,
'errorCode' => null,
'errorText' => null,
]
];
// Common setup for API credentials
$merchantAuthentication = new AnetAPI\MerchantAuthenticationType();
$merchantAuthentication->setName(get_option('authorizenet_app_login_id', true));
$merchantAuthentication->setTransactionKey(get_option('authorizenet_transaction_key', true));
// Set up a payment schedule
$paymentSchedule = new AnetAPI\PaymentScheduleType();
$paymentScheduleInterval = new AnetAPI\PaymentScheduleType\IntervalAType();
if ($intervalType === 'monthly') {
$paymentScheduleInterval->setLength(1);
$paymentScheduleInterval->setUnit("months");
}
// else if ($intervalType === 'annually') {
// $paymentScheduleInterval->setLength(12);
// $paymentScheduleInterval->setUnit("months");
// }
$paymentSchedule->setInterval($paymentScheduleInterval);
$paymentSchedule->setStartDate($startDate);
$paymentSchedule->setTotalOccurrences("9999"); // Indefinite
$cardNumber = sanitize_text_field($form_data['card_number']);
$expDateInput = '10/25';//sanitize_text_field($form_data['exp_date']);
$donorEmail = 'test@gmail.com';//sanitize_email($form_data['donor_email']);
// Create the payment data for a credit card
$creditCard = new AnetAPI\CreditCardType();
$creditCard->setCardNumber($cardNumber);
// Get expiration date in 'MM/YY' format
$expDateInput = $expDateInput;
// Create a DateTime object from the input
$expDate = DateTime::createFromFormat('m/y', $expDateInput);
// Format the date to 'YYYY-MM'
$expDateFormatted = $expDate ? $expDate->format('Y-m') : '';
// Set the formatted expiration date to the credit card object
$creditCard->setExpirationDate($expDateFormatted);
// Add the payment data to a paymentType object
$paymentOne = new AnetAPI\PaymentType();
$paymentOne->setCreditCard($creditCard);
// Create subscription
$subscription = new AnetAPI\ARBSubscriptionType();
$subscription->setPaymentSchedule($paymentSchedule);
$subscription->setAmount($amount);
$subscription->setPayment($paymentOne);
// Create order information (optional)
$order = new AnetAPI\OrderType();
$order->setDescription("Yad Batya Donation");
$subscription->setOrder($order);
// Set the customer's Bill To address (optional)
$customerAddress = new AnetAPI\CustomerAddressType();
$customerAddress->setFirstName($form_data['donor_fname']);
$customerAddress->setLastName($form_data['donor_lname']);
$customerAddress->setAddress($form_data['donor_address']);
$customerAddress->setCity($form_data['donor_city']);
$customerAddress->setState($form_data['donor_state']);
$subscription->setBillTo($customerAddress);
// Set the customer's identifying information
$customerData = new AnetAPI\CustomerType();
// $customerData->setPhoneNumber($form_data['donor_phone']);
$customerData->setEmail($donorEmail);
$subscription->setCustomer($customerData);
// Send request to create the subscription
$request = new AnetAPI\ARBCreateSubscriptionRequest();
$request->setMerchantAuthentication($merchantAuthentication);
$request->setSubscription($subscription);
$controller = new AnetController\ARBCreateSubscriptionController($request);
$response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::SANDBOX);
// $response = $controller->executeWithApiResponse(\net\authorize\api\constants\ANetEnvironment::PRODUCTION);
// Handle the response
if ($response != null) {
$messages = $response->getMessages();
// Check for successful subscription creation
if ($messages != null && $messages->getResultCode() == "Ok") {
$subscriptionId = $response->getSubscriptionId();
$successMessage = $messages->getMessage()[0]->getText();
$subscriptionResponse['success'] = true;
$subscriptionResponse['data'] = [
'subscriptionStatus' => 'success',
'message' => "Subscription created successfully. $successMessage",
'subscriptionId' => $subscriptionId,
'errorCode' => null,
'errorText' => null,
];
} else {
// Handle error if subscription creation failed
if ($messages != null && $messages->getMessage() != null) {
$error = $messages->getMessage()[0];
$errorCode = $error->getCode();
$errorText = $error->getText();
$subscriptionResponse['data'] = [
'subscriptionStatus' => 'error',
'message' => "Subscription creation failed: $errorText",
'errorCode' => $errorCode,
'errorText' => $errorText,
'subscriptionId' => null,
];
// Log the error for debugging
error_log("Authorize.NET Subscription Error: Code $errorCode, Message: $errorText");
} else {
// Fallback for unhandled errors
$subscriptionResponse['data']['message'] = "Unhandled error occurred while creating the subscription.";
}
}
} else {
// No response object returned
$subscriptionResponse['data']['message'] = "Subscription creation failed with no response.";
}
return $subscriptionResponse;
}