File: /home/kochikidswysewor/www/wp-content/themes/children-charity-child/test-mail.php
<?php
$parse_uri1 = explode('wp-content', $_SERVER['SCRIPT_FILENAME']);
$parse_uri = explode('children-charity-child', $_SERVER['SCRIPT_FILENAME']);
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
use PHPMailer\PHPMailer\Exception;
require_once($parse_uri1[0].'wp-load.php');
$id = 17973;
$args = array(
'post_type' => 'donations',
'p' => $id,
'posts_per_page' => 1
);
$query = new WP_Query( $args );
if( $query->have_posts() ) {
while( $query->have_posts() ) {
$query->the_post();
$amount= get_field('amount',$id);
$case = get_field('case',$id);
$transaction_id = get_field('transaction_id',$id);
$date = get_field('transaction_date',$id);
$name = get_field('name',$id);
$admin_email = get_option( 'admin_email' );
$agency = get_field('agency',$id);
$agencyEmail = $agency->user_email;
$to = [$agencyEmail, $admin_email,'p.rahul.techintl@gmail.com'];
$from_mail = "info@kochikids.org";
$subject = "Kochi Kids -Contribution Received";
$email = get_field('email',$id);
$current_user = wp_get_current_user($id);
if($email == '') {
$email = $current_user->user_email;
}
if ( is_user_logged_in() ) {
$name = $current_user->first_name;
} else {
$name = get_field('name',$id);
}
$to_ = $email;
$subject_confirmation = "Confirmation - Kochi Kids";
$body = '
<table width="700" style="border-collapse:collapse;border:1px solid #444;">
<tbody>
<tr>
<th colspan="2"><a href="'. get_site_url().'" target="_blank" style="color: #dc3779;"><img src="'.get_stylesheet_directory_uri().'/img/mail-template.jpg"></a></th>
</tr>
<tr>
<td colspan="2" colspan="2" style="padding:7px 15px;border:1px solid #444;">Received a contibution.Details are below:</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Name:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$name.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Amount:</td>
<td style="padding:7px 15px;border:1px solid #444;">CAD '.$amount.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Cause:</td>
<td style="padding:7px 15px;border:1px solid #444;">Contribute for '.$case->post_title.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Transaction ID:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$transaction_id.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Transaction Date:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$date.'</td>
</tr>
</tbody>
<tfoot style="text-align: center;background-color: #dc3779;">
<tr>
<td colspan="2" style="color: #ffffff;padding:7px 15px;">
<a href="'. get_site_url().'" target="_blank" style="color: #fff;">Kochi Kids</a>
</td>
</tr>
</tfoot>
</table>';
$msg_user= '<table width="700" style="border-collapse:collapse;border:1px solid #444;">
<tbody>
<tr>
<th colspan="2"><a href="'. get_site_url().'" target="_blank" style="color: #dc3779;"><img src="'.get_stylesheet_directory_uri().'/img/mail-template.jpg"></a></th>
</tr>
<tr>
<td colspan="2" colspan="2" style="padding:7px 15px;border:1px solid #444;">Thank you for contacting Kochi Kids. We have successfully received your payment.The details of your Contribution are provided below for your reference:</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Name:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$name.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Amount:</td>
<td style="padding:7px 15px;border:1px solid #444;">CAD '.$amount.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Cause:</td>
<td style="padding:7px 15px;border:1px solid #444;">Contribute for '.$case->post_title.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Transaction ID:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$transaction_id.'</td>
</tr>
<tr>
<td style="padding:7px 15px;border:1px solid #444;">Transaction Date:</td>
<td style="padding:7px 15px;border:1px solid #444;">'.$date.'</td>
</tr>
</tbody>
<tfoot style="text-align: center;background-color: #dc3779;">
<tr>
<td colspan="2" style="color: #ffffff;padding:7px 15px;">
<a href="'. get_site_url().'" target="_blank" style="color: #fff;">Kochi Kids</a>
</td>
</tr>
</tfoot>
</table>';
}
}
$mail1 = new PHPMailer(true);
try {
//Server settings
//$mail1->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail1->isSMTP(); //Send using SMTP
$mail1->Host = 'mail.kochikids.org'; //Set the SMTP server to send through
$mail1->SMTPAuth = true; //Enable SMTP authentication
$mail1->Username = 'info@kochikids.org'; //SMTP username
$mail1->Password = '{iXTZ%J%#RP8'; //SMTP password
$mail1->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail1->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail1->setFrom('info@kochikids.org');
foreach ($to as $key ) {
$mail1->addAddress($key);
}
//Add a recipient
if($from_mail){
$mail1->addReplyTo($from_mail);
}
$mail1->isHTML(true);
$mail1->Subject = $subject;
$mail1->MsgHTML($body);
$send = $mail1->send();
}catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail1->ErrorInfo}";
}
$mail2 = new PHPMailer(true);
try {
//Server settings
//$mail2->SMTPDebug = SMTP::DEBUG_SERVER; //Enable verbose debug output
$mail2->isSMTP(); //Send using SMTP
$mail2->Host = 'mail.kochikids.org'; //Set the SMTP server to send through
$mail2->SMTPAuth = true; //Enable SMTP authentication
$mail2->Username = 'info@kochikids.org'; //SMTP username
$mail2->Password = '{iXTZ%J%#RP8'; //SMTP password
$mail2->SMTPSecure = PHPMailer::ENCRYPTION_SMTPS; //Enable implicit TLS encryption
$mail2->Port = 465; //TCP port to connect to; use 587 if you have set `SMTPSecure = PHPMailer::ENCRYPTION_STARTTLS`
//Recipients
$mail2->setFrom('info@kochikids.org');
$mail2->addAddress($to_);
if($from_mail){
$mail2->addReplyTo($from_mail);
}
$mail2->isHTML(true);
$mail2->Subject = $subject_confirmation;
$mail2->MsgHTML($msg_user);
$send = $mail2->send();
}catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail2->ErrorInfo}";
}
?>