I am trying to create a simple contact form using PHPMailer and here is what i got so far:
contact.php:
<?php
require 'includes/config.php';
require 'includes/phpmailer/PHPMailerAutoload.php';
function sanitize($text) {
$text = trim($text);
if (get_magic_quotes_gpc()) {
$text = stripslashes($text);
}
$text = strip_tags($text);
return $text;
}
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$entries = array();
$response = array();
// Escape and extract all the post values
foreach ($_POST as $key => $value) {
$entries[$key] = sanitize($value);
}
$name = $entries['cf_name'];
$email = $entries['cf_email'];
$message = $entries['cf_message'];
$subject = 'Contact form';
$replySubject = 'Contact form';
$mailBody = '<b>Email message</b>';
// Check is an AJAX request
if (!empty($_SERVER['HTTP_X_REQUESTED_WITH']) && strtolower($_SERVER['HTTP_X_REQUESTED_WITH']) == 'xmlhttprequest') {
// Create a new PHPMailer instance
$mail = new PHPMailer;
// Tell PHPMailer to use SMTP
$mail->isSMTP();
// Set the hostname of the mail server
$mail->Host = MAIL_HOST;
// Set the SMTP port number - 587 for authenticated TLS
$mail->Port = MAIL_PORT;
// Set the encryption system to use - ssl (deprecated) or tls
$mail->SMTPSecure = 'tls';
// Whether to use SMTP authentication
$mail->SMTPAuth = true;
// Username to use for SMTP authentication
$mail->Username = MAIL_USER;
// Password to use for SMTP authentication
$mail->Password = MAIL_PASS;
// Set who the message is to be sent from
$mail->setFrom($email, $name);
// Set an alternative reply-to address
$mail->addReplyTo($email, $name);
// Set who the message is to be sent to
$mail->addAddress(MAIL_ADDR);
// Set the subject line
$mail->Subject = 'Formularz kontaktowy';
// Set email format to HTML
$mail->isHTML(true);
$mail->CharSet = 'UTF-8';
// HTML version
$mail->Body = $mailBody;
// Convert HTML into a basic plain-text alternative body
$mail->AltBody = strip_tags($mailBody);
// send the message
if ($mail->send()) {
$response['result'] = 1;
} else {
$response['result'] = 0;
$response['error'] = $mail->ErrorInfo;
}
echo json_encode($response);
} else {
header('Location: ' . BASE_URL);
exit();
}
} else {
header('Location: ' . BASE_URL);
exit();
}
config.php
<?php
define('BASE_URL', 'http://example.com');
define('MAIL_HOST', 'smtp.gmail.com');
define('MAIL_PORT', 587);
define('MAIL_USER', 'mygmailemail#gmail.com');
define('MAIL_PASS', 'mygmailpassword');
define('MAIL_ADDR', 'example#email.com');
Client-Side:
$('form').on('submit', function(e) {
e.preventDefault();
var formData = $(this).serializeArray();
var t1 = window.performance.now();
$.ajax({
type: 'POST',
url: this.action,
data: formData
})
.done(function(response) {
console.log('DONE', response);
var t2 = window.performance.now();
console.log('time', (t2 - t1) / 1000);
})
.fail(function(response) {
console.log('FAIL', response);
});
});
I am testing this code locally with EasyPHP Server. As you can see above i log time inside ajax done callback and the average time to send an email is 3-5 seconds which i found ridiculously slow. I am not PHP developer so I have no idea why is it so slow. Is it EasyPHP fault or something else I did wrong? Can you please tell how can I improve this code to send out emails faster?
Related
hello im trying to send mail with input form javascript jspdf via phpmailer
mail sent ok but file were broken if i get $_POST['data'] through original php file.
how i can deliver jspdf file with $_POST['data'] to phpmailer?
i tried many ways but it didn't help much.
thank you for reading this
form_input.php
var create_pdf = document.getElementById("create_pdf");
create_pdf.addEventListener('click', function (event) {
html2canvas($('#pdf_wrap')[0] ,{
//logging : true,
//proxy: "html2canvasproxy.php",
allowTaint : true,
useCORS: true,
scale : 2
}).then(function(canvas) {
var imgData = canvas.toDataURL('image/jpeg');
var doc = new jsPDF("p", "px");
var options = {
pagesplit: true
};
var imgWidth = 210;
var pageHeight = 295;
var imgHeight = canvas.height * imgWidth / canvas.width;
var heightLeft = imgHeight;
var doc = new jsPDF('p', 'mm');
var position = 0;
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
while (heightLeft >= 0) {
position = heightLeft - imgHeight;
doc.addPage();
doc.addImage(imgData, 'PNG', 0, position, imgWidth, imgHeight);
heightLeft -= pageHeight;
}
//Send mail on other php
$.post("mail_send.php",
{
data: doc.output('datauristring')
}, function () {}).done(function() {/*SOME CODE*/});
// doc.save( 'file.pdf');
});
});
mail_send.php
require 'plugin/PHPMailer/class.phpmailer.php';
require 'plugin/PHPMailer/class.smtp.php';
require 'plugin/PHPMailer/PHPMailerAutoload.php';
if(!empty($_POST['data']))
{
echo $_POST['data'];
$mail = new PHPMailer(true);
try {
//Server settings
$mail->SMTPDebug = false; // Enable verbose debug output
$mail->isSMTP(); // Send using SMTP
$mail->Host = 'smtp.test.com'; // Set the SMTP server to send through
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'smtpid#dot.com'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->Port = 465;
$mail->SMTPAuth = true;
$mail->SMTPKeepAlive = true; // TCP port to connect to
$mail->SMTPSecure = 'ssl';
$mail->setFrom('setmail#mail.com', 'Mailer');
$mail->addAddress('user#mail.com', 'Joe User'); // Add a recipient
$mail->CharSet = "utf-8";
// ----------Attachments this doesn't work. delivered broken pdf file.
$base = explode('data:application/pdf;base64,', $_POST['data']);
$mail->addStringAttachment($base, 'pdfName.pdf');
// -----------
$mail->isHTML(true); // Set email format to HTML
$mail->Body = $body;
$mail->Subject = 'Here is the subject';
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
$mail->send();
echo 'Message has been sent';
} catch (Exception $e) {
echo "Message could not be sent. Mailer Error: {$mail->ErrorInfo}";
}
You need to double check your data, but I think is the problem
$base = explode('data:application/pdf;base64,', $_POST['data']);
$mail->addStringAttachment($base, 'pdfName.pdf');
This will not result in a PDF attachment; it will result in a base64-encoded PDF attachment tagged as a PDF, which will then be base64-encoded a second time by PHPMailer because it can't know what data you are providing. So decode the PDF data before attaching it:
$mail->addStringAttachment(base64_decode($base), 'pdfName.pdf');
i made a php function to send mail using phpmailer. but, there is a problem in the function. it neither send mail nor shows error. please help me out. i'm fetching mail body and some other details from other functions and its working fine except it doesn't send mail and i think there must be some problem with the host,port,username,etc.
please help me out.
thanks
my funciton:
public static function sendEmail($data) {
$r_error = 1;
$r_message = "";
$r_data = array();
$q = "select * from config where type='email_detail'";
$r = self::DBrunQuery($q);
$row = self::DBfetchRow($r);
$detail = json_decode($row['value'], true);
include "phpmailer/PHPMailerAutoload.php";
if (!empty($data['email'])) {
foreach ($data as $var) {
$work_email = 'fahadansari12feb#gmail.com'; //$var['email_id'];
$name = 'fahad'; //$var['name'];
$subject = $var['subject'];
$body = $var['body'];
$cc = $var['cc_detail'];
$bcc = $var['bcc_detail'];
$file_upload = $var['upload_file'];
$mail = new PHPMailer;
$mail->isSMTP();
$mail->SMTPDebug = 0;
$mail->Debugoutput = 'html';
$mail->Host = '5.9.144.226'; //$detail['host'];
$mail->Port = '2222'; //$detail['port'];
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = 'fahadansari12feb#gmail.com'; //$detail['username']; //sender email address
$mail->Password = 'mypassword'; //$detail['password']; // sender email password
$mail->setFrom('hr#excellencetechnologies.in', 'Excellence Technologies'); // name and email address from which email is send
$mail->addReplyTo('hr#excellencetechnologies.in', 'Excellence Technologies'); // reply email address with name
$mail->addAddress($work_email, $name); // name and address to whome mail is to send
if (sizeof($cc) > 0) {
foreach ($cc as $d) {
$mail->addCC($d[0], $d[1]);
}
}
if (sizeof($bcc) > 0) {
foreach ($bcc as $d2) {
$mail->addBCC($d2[0], $d2[1]);
}
}
$mail->Subject = $subject; // subject of email message
$mail->msgHTML($body); // main message
// $mail->AltBody = 'This is a plain-text message body';
//Attach an image file
if (sizeof($file_upload) > 0) {
foreach ($file_upload as $d3) {
$mail->addAttachment($d3);
}
}
//send the message, check for errors
if (!$mail->send()) {
$row3 = $mail->ErrorInfo;
} else {
$row3 = "Message sent";
}
}
}
if ($row3 != "Message sent") {
$r_error = 1;
$r_message = $row3;
$r_data['message'] = $r_message;
} else {
$r_error = 0;
$r_message = "Message Sent";
$r_data['message'] = $r_message;
}
$return = array();
$return['error'] = $r_error;
$return['data'] = $r_data;
return $return;
}
You've not posted enough info, but I'm going to guess your problem. You're enabling TLS, but you're connecting to an IP address rather than a host name, so your host name will never match the name on the certificate and you will get a TLS validation failure on SMTP connections.
Connect to a named host with a valid certificate, or disable certificate checks (see PHPMailer docs for how to do that), though that's not recommended.
You're also using an old version of PHPMailer, so upgrade.
I am new to PHP and trying to implement Google reCaptcha v2 using PHP and AJAX using either CurlPost() or SocketPost() methods. Currently everything runs fine with file_get_contents() but my provider is going to lock it down soon so I need to refactor my code. Somehow I ran into problem with implementing CurlPost() or SocketPost() - whenever I try to use either of them, nginx responds with 403 stating that Not a POST request (it is hardcoded in one of the else clauses).
What exactly did I overlook with POST? Below are two pieces of code, one is working perfectly with file_get_contents() and second is code in question throwing 403.
Working one
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require("PHPMailer.php");
require("Exception.php");
require("SMTP.php");
require('recaptcha-master/src/autoload.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST["tel"]);
$message = trim($_POST["message"]);
$recaptchaSecret = "6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf";
$captcha = '';
if(isset($_POST["captcha"]) && !empty($_POST["captcha"])){
$captcha=$_POST["captcha"];
}
if(!$captcha){
echo 'Prove that you are human';
exit;
}
$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf&response=".$captcha."&remoteip=".$_SERVER["REMOTE_ADDR"]);
$obj = json_decode($response);
if($obj->success == true) {
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR empty($tel) OR empty($captcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Build the email content.
$email_content = "Имя: $name\n";
$email_content .= "Телефон: $tel\n";
$email_content .= "Email: $email\n";
$email_content .= "Сообщение: $message\n";
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
//$mail->setFrom($name, $email);
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo "success";
}
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "Something went wrong. Please try again";
}
?>
And not working, giving 403:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require("PHPMailer.php");
require("Exception.php");
require("SMTP.php");
require('recaptcha-master/src/autoload.php');
if ($_SERVER["REQUEST_METHOD"] == "POST") {
// Get the form fields and remove whitespace.
$name = strip_tags(trim($_POST["name"]));
$name = str_replace(array("\r","\n"),array(" "," "),$name);
$email = filter_var(trim($_POST["email"]), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST["tel"]);
$message = trim($_POST["message"]);
$recaptcha = $_POST["g-recaptcha-response"];
$secret = '6LcjwkUUAAAAAENXcZtla40jNuPJGblZkYxLkXvf';
}
//$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\CurlPost());
$recaptcha = new \ReCaptcha\ReCaptcha($secret, new \ReCaptcha\RequestMethod\SocketPost());
$resp = $recaptcha->verify($_POST['g-recaptcha-response'], $_SERVER['REMOTE_ADDR']);
if ($resp->isSuccess()) {
// Check that data was sent to the mailer.
if ( empty($name) OR empty($message) OR empty($tel) OR empty($recaptcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo "Oops! There was a problem with your submission. Please complete the form and try again.";
exit;
}
// Build the email content.
$email_content = "Имя: $name\n";
$email_content .= "Телефон: $tel\n";
$email_content .= "Email: $email\n";
$email_content .= "Сообщение: $message\n";
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo "success";
} else {
// Not a POST request, set a 403 (forbidden) response code.
http_response_code(403);
echo "Something went wrong. Please try again";
}
?>
Really thankful for any hints! Thank you in advance.
Finally I found working solution with curl not using standard google recaptcha library, just plain curl. The code needs a lot of cleaning but it's working. Here it is:
<?php
use PHPMailer\PHPMailer\PHPMailer;
use PHPMailer\PHPMailer\SMTP;
require('PHPMailer.php');
require('Exception.php');
require('SMTP.php');
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
$name = strip_tags(trim($_POST['name']));
$name = str_replace(array('\r','\n'),array(' ',' '),$name);
$email = filter_var(trim($_POST['email']), FILTER_SANITIZE_EMAIL);
$tel = trim($_POST['tel']);
$message = trim($_POST['message']);
$secret = '6LcjwkUUAAAAAENXwZtla40jNuPJGblZkYxLkXvf';
$captcha = '';
if(isset($_POST['captcha']) && !empty($_POST['captcha'])){
$captcha=$_POST['captcha'];
}
if(!$captcha){
echo 'Prove that you are human';
exit;
}
$fields = array(
'secret' => $secret,
'response' => $_POST['captcha'],
'remoteip' => $_SERVER['REMOTE_ADDR']
);
$verifyResponse = curl_init('https://www.google.com/recaptcha/api/siteverify');
curl_setopt($verifyResponse, CURLOPT_RETURNTRANSFER, true);
curl_setopt($verifyResponse, CURLOPT_TIMEOUT, 15);
curl_setopt($verifyResponse, CURLOPT_POSTFIELDS, http_build_query($fields));
$responseData = json_decode(curl_exec($verifyResponse));
curl_close($verifyResponse);
if ($responseData->success) {
if ( empty($name) OR empty($message) OR empty($tel) OR empty($captcha) OR !filter_var($email, FILTER_VALIDATE_EMAIL)) {
// Set a 400 (bad request) response code and exit.
http_response_code(400);
echo 'Oops! There was a problem with your submission. Please complete the form and try again.';
exit;
}
// Build the email content.
$email_content = 'Имя: $name\n';
$email_content .= 'Телефон: $tel\n';
$email_content .= 'Email: $email\n';
$email_content .= 'Сообщение: $message\n';
// Send the email.
$mail = new PHPMailer();
//Server settings
$mail->SMTPDebug = 0; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'domain.tld'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = 'info'; // SMTP username
$mail->Password = 'password'; // SMTP password
$mail->SMTPSecure = 'tls'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 587; // TCP port to connect to
//Recipients
$mail->setFrom('info#domain.tld', 'DOMAIN.TLD');
$mail->addAddress('info#domain.tld', 'Information'); // Add a recipient
$mail->addReplyTo('info#domain.tld', 'Information');
//Content
$mail->Subject = 'Новое сообщение с сайта DOMAIN.TLD' ;
$mail->Body = $email_content;
$success = $mail->send();
echo 'success';
}
} else {
http_response_code(403);
echo 'Something went wrong. Please try again';
}
?>
I am design a form for sending mail in bulk via phpMailer, for example i want to send a mail to 50 persons.but the issue is after sending mail 10 to 15 persons my form gives an file not found exception.
my ajax call is given below
.on('success.form.bv', function(e) {
e.preventDefault();
$('#send_email_next').modal({
backdrop: 'static'
});
$.ajax({
type: "POST",
url: "email_next.php",
data: $("#emailform").serialize(),
success: function(html){ $("#modal_body").html(html);}
});
});
Phpmailer function called in email_next.php is given below
require_once("class.phpmailer.php");
require_once("class.smtp.php");
$mail = new PHPMailer();
$body=" ";
set_time_limit(0);
$mail->IsSMTP();
$mail->Timeout = 10000;
$mail->SMTPKeepAlive = true;
$mail->SMTPDebug = false;
$mail->do_debug = 0;
$mail->SMTPAuth = true; // enable SMTP authentication
$mail->SMTPSecure = 'tls'; // sets the prefix to the servier
$mail->Host = "smtp.gmail.com"; // sets GMAIL as the SMTP server
$mail->Port = 587; // set the SMTP port
$mail->Username = $account_user_name; // GMAIL username
$mail->Password = $password; // GMAIL password
$mail->From = $account_user_name;
$mail->FromName = 'Rayat Bahra Group';
$mail->Subject = $_POST['subject'];
$mail->AltBody = '';
$mail->WordWrap = 50;
$mail->MsgHTML($body);
$mail->MsgHTML($content);
$mail->IsHTML(true); // send as HTML
$SN = 0;
$error_mail=0;
$total_mails_to_send = count($email_array);
foreach($email_array as $recipient_address)
{
$mail2 = clone $mail;
$mail2->MsgHTML($content);
$mail2->AddAddress(trim($recipient_address));
$status = $mail2->Send();
if($status)
{
$SN++;
}
else{
$error_mail = 1;
}
echo $SN." out of ".$total_mails_to_send. " sent <br>";
}
if($error_mail == 1)
{
echo "Message was not sent <br />PHPMailer Error: " . $mail->ErrorInfo;
}
else{
echo "Message has been sent";
}
$mail->SmtpClose();
I've never used ajax before but from what I can tell that's the solution to my problem, basically I'm using a PHPmailer form on indk.org/contact.html and when you hit submit it displays a new window (taking you away from the website nav) with {"success":{"title":"Message Sent"}} shown
How do I stop this happening, or at the very least, have a message sent confirmation appear on the webpage itself, want to avoid taking people off site as much as I can as it's a personal portfolio.
Welcome any aid! Thanks :) D
<?php
require '../_lib/phpmailer/PHPMailerAutoload.php';
// CONFIG YOUR FIELDS
//============================================================
$name = filter_var($_POST["name"], FILTER_SANITIZE_STRING);
$email = filter_var($_POST["email"], FILTER_SANITIZE_EMAIL);
$formMessage = filter_var($_POST["message"], FILTER_SANITIZE_STRING);
// CONFIG YOUR EMAIL MESSAGE
//============================================================
$message = '<p>The following request was sent from: </p>';
$message .= '<p>Name: ' . $name . '</p>';
$message .= '<p>Email: ' . $email . '</p>';
$message .= '<p>Message: ' . $formMessage .'</p>';
// CONFIG YOUR MAIL SERVER
//============================================================
$mail = new PHPMailer;
$mail->isSMTP(); // Enable SMTP authentication
$mail->SMTPAuth = true; // Set mailer to use SMTP
$mail->Host = 'mailout.one.com'; // Specify main and backup server (this is a fake name for the use of this example)
$mail->Username = 'dk#indk.org'; // SMTP username
$mail->Password = 'XXX'; // SMTP password
$mail->SMTPSecure = 'SSL'; // Enable encryption, 'ssl' also accepted
$mail->Port = 587;
$mail->From = 'dk#indk.org';
$mail->FromName = $name;
$mail->AddReplyTo($email,$name);
$mail->addAddress('dk#indk.org', $name); // Add a recipient
$mail->WordWrap = 50; // Set word wrap to 50 characters
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = 'Contact request';
$mail->Body = $message;
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
if(!$mail->send()) {
$data['error']['title'] = 'Message could not be sent.';
$data['error']['details'] = 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
$data['success']['title'] = 'Message Sent, click back to return to indk.org';
echo json_encode($data);
?>
$(document).ready(function() {
'use strict';
$('#contact-form').validate({
// Override to submit the form via ajax
submitHandler: function(form) {
$('#contact-panel').portlet({
refresh:true
});
$.ajax({
type:$(form).attr('method'),
url: $(form).attr('action'),
data: $(form).serialize(),
dataType: 'json',
success: function(data){
console.log(data);
//Set your Success Message
clearForm("Thank you for Contacting Us! We will be in touch");
},
error: function(err){
$('#contact-panel').portlet({
refresh:false,
//Set your ERROR Message
error:"We could not send your message, Please try Again"
});
}
});
return false; // required to block normal submit since you used ajax
}
});
function clearForm(msg){
$('#contact-panel').html('<div class="alert alert-success" role="alert">'+msg+'</div>');
}
$('#contact-panel').portlet({
onRefresh: function() {
}
});
});
You can do it either way. You can use a simple bootstrap pop-up to show the confirmation or as you said you can use AJAX.