CF7 Autoresponder (mail2) Delay Send - php

Context
I'm trying to delay sending the autoresponder (mail2) in contact form 7 for 8hours after the submission of the initial form. I'm thinking something like this:
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else"); function wpcf7_do_something_else($cf7) {
// get the contact form object
$wpcf = WPCF7_ContactForm::get_current();
// if you wanna check the ID of the Form $wpcf->id
if (/*Perform check here*/) {
// If you want to skip mailing the data, you can do it...
$wpcf->skip_mail = true;
}
return $wpcf; }
Problem
Not sure what filter/hooks to use.

Related

Echo Custom response message , contact form 7 before send email hook

I want to show a custom message below or above contactform7, without sending the email. I tired it using before_send_email function, but nothing is working. below is the function I have used.
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else($cf7) {
$wpcf->skip_mail = true;
// Here I tried to use jquery or wordpress filter function to display custom message. but nothing is displaying.
return $wpcf;
}
Please help
to return a custom message on the form submission, you can use the filter wpcf7_ajax_json_echo
try that :
add_filter("wpcf7_ajax_json_echo", function ($response, $result) {
$response["message"] = "a custom message";
return $response;
});

A simple email client/contact form is returning a "5.5.4 Invalid Domain Error" and I have exhausted all my resources attempting to solve it

I've posted this question twice in the last two days and I have really run dry of solutions. I'm creating a very simple comment box that when filled out sends the comment in an email to my company's safety department. I have been receiving this 5.5.4 Invalid Domain Error for the last couple days.
It's SMTP and TLS. The port and server name is correct. The server allows for anonymous emails, and does not validate. I'm using the Swiftmailer library so I shouldn't need to script a ELHO/HELO. The only property of the email that's not defined/hard coded is the body of the message. This is the code for my controller (index.php).
// Initialize Swiftmailer Library
require_once("./swiftmailer/lib/swift_required.php");
// Class that contains the information of the email that will be sent (from, to, etc.)
require_once("./classes/EmailParts.php");
// The class that "breaks" the data sent with the HTML form to a more "usable" format.
require_once("./classes/ContactForm.php");
// =====================
// Main Configuration
// =====================
define("EMAIL_SUBJECT", "Safety Concerns");
define("EMAIL_TO", "safetydepartment#company.com");
define("EMAIL_FROM", "safetydepartment#company.com");
// SMTP Configuration
define("SMTP_SERVER", 'exchange.company.local');
define("SMTP_PORT", 25);
function main($contactForm) {
// Checks if something was sent to the contact form, if not, do nothing
if (!$contactForm->isDataSent()) {
return;
}
// Validates the contact form and checks for errors
$contactForm->validate();
$errors = array();
// If the contact form is not valid:
if (!$contactForm->isValid()) {
// gets the error in the array $errors
$errors = $contactForm->getErrors();
} else {
// If the contact form is valid:
try {
// send the email created with the contact form
$result = sendEmail($contactForm);
// after the email is sent, redirect and "die".
// We redirect to prevent refreshing the page which would resend the form
header("Location: ./success.php");
die();
} catch (Exception $e) {
// an error occured while sending the email.
// Log the error and add an error message to display to the user.
error_log('An error happened while sending email contact form: ' . $e->getMessage());
$errors['oops'] = 'Ooops! an error occured while sending your email! Please try again later!';
}
}
return $errors;
}
// Sends the email based on the information contained in the contact form
function sendEmail($contactForm) {
// Email part will create the email information needed to send an email based on
// what was inserted inside the contact form
$emailParts = new EmailParts($contactForm);
// This is the part where we initialize Swiftmailer with
// all the info initialized by the EmailParts class
$emailMessage = Swift_Message::newInstance()
->setSubject($emailParts->getSubject())
->setFrom($emailParts->getFrom())
->setTo($emailParts->getTo())
->setBody($emailParts->getBodyMessage());
// Another Swiftmailer configuration..
$transport = Swift_SmtpTransport::newInstance(SMTP_SERVER, SMTP_PORT, 'tls');
$mailer = Swift_Mailer::newInstance($transport);
$result = $mailer->send($emailMessage);
return $result;
}
// Initialize the ContactForm with the information of the form and the possible uploaded file.
$contactForm = new ContactForm($_POST, $_FILES);
// Call the "main" method. It will return a list of errors.
$errors = main($contactForm);
// Call the "contactForm" view to display the HTML contact form.
require_once("./views/contactForm.php");
I've posted the entirety of my code at Dropbox. There's not much, but I think the problem must lie in the Index.

Wordpress: integrate CRM (solve360) with Contact Form 7

I am trying to let a contact form (Contact Form 7) on a WordPress site create new contacts in my CRM program (solve360). To make it easier, I also activated a plugin (Forms: 3rd Party Integration) in which I defined a submission url and field mapping. Part of it works, but I am missing something simple here...
When pressing the send button, the data is sent to an email address (success) and to solve360 (not yet successfully). I actually receive a message that a new contact was created in solve360, however all the fields are empty. So I am guessing the problem is that the form fields are not properly transferred to the solve360 fields. However, I am using this template from solve360:
// REQUIRED Edit with the email address you login to Solve360 with
define('USER', '****************');
// REQUIRED Edit with token, Solve360 menu > My Account > API Reference > API Token
define('TOKEN', '*****************');
// Get request data
$requestData = array();
parse_str($_SERVER['QUERY_STRING'], $requestData);
// Configure service gateway object
require 'Solve360Service.php';
$solve360Service = new Solve360Service(USER, TOKEN);
//
// Preparing the contact data
//
$contactFields = array('firstname','lastname','businessemail','businessphonedirect','name','homeaddress','cus tom10641628','custom11746174','custom13346238');
$contactData = array();
// adding not empty fields
foreach ($contactFields as $solve360FieldName => $requestFieldName) {
if ($requestData[$requestFieldName]) {
$contactData[$solve360FieldName] = $requestData[$requestFieldName];
}
}
//
// Saving the contact
//
// If there was business email provided:
// check if the contact already exists by searching for a matching email address.
// if a match is found update the existing contact, otherwise create a new one.
//
if ($contactData['businessemail']) {
$contacts = $solve360Service->searchContacts(array(
'filtermode' => 'byemail',
'filtervalue' => $contactData['businessemail'],
));
}
if (isset($contacts) && (integer)$contacts->count > 0) {
$contactId = (integer)current($contacts->children())->id;
$contactName = (string)current($contacts->children())->name;
$contact = $solve360Service->editContact($contactId, $contactData);
} else {
$contact = $solve360Service->addContact($contactData);
$contactName = (string)$contact->item->name;
$contactId = (integer)$contact->item->id;
}
if (isset($contact->errors)) {
// Email the error
mail(
USER,
'Error while adding contact to Solve360',
'Error: ' . $contact->errors->asXml()
);
die ('System error');
} else {
// Email the result
mail(
USER,
'Contact posted to Solve360',
'Contact "' . $contactName . '" https://secure.solve360.com/contact/' . $contactId . ' was posted to Solve360'
);
}
In their example, they use a contact form with method="get" instead of method="post", however in the user interface of Contact Form 7, I believe the method is fixed to "post". Could this be the problem?
Or is there a different issue? Note that an empty contact is created at the moment. I can provide field mapping details and Forms 3rd party integration does allow hooks, if that helps in anyway.
Any help would be really appreciated! Thanks.
I discovered that the action method (POST) of the 3rd party plugin was not matching the expected action method (GET) of the Solve360 script. Therefore, I had to remove the following from the script:
// Get request data
$requestData = array();
parse_str($_SERVER['QUERY_STRING'], $requestData);
and change the following piece of code from
// adding not empty fields
foreach ($contactFields as $solve360FieldName => $requestFieldName) {
if ($requestData[$requestFieldName]) {
$contactData[$solve360FieldName] = $requestData[$requestFieldName];
}
}
to
// adding not empty fields
foreach ($contactFields as $solve360FieldName => $requestFieldName) {
if ($_POST[$requestFieldName]) {
$contactData[$solve360FieldName] = $_POST[$requestFieldName];
}
}
Hope this will help someone who is connecting Contact Form 7 to their Solve360 database.

wordpress contact form 7 disable email

I am facing an issue with Contact Form 7 for Wordpress. I want to disable the email notification which i did using
demo_mode: on
At the same time i want to redirect on submit which i used to do using
on_sent_ok: "location = 'http://domain.com/about-us/';"
Both would work when used individually.But i want to use both at the same time.
I tried doing
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
Doesnt seem to work. Kindly advice.
The plugin author has changed as of at least 4.0 the way you should do this again. The skip_mail property is now private :
class WPCF7_Submission {
private $skip_mail = false;
...
}
You should use this filter : wpcf7_skip_mail
For example :
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
if(/* YOUR TEST HERE */){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');
The author of the plugin Contact Form 7 has refactored some of the code for its version 3.9 and since then the callback function for the hook wpcf7_before_send_mail must be written differently.
To prevent Contact Form 7 from sending the email and force it to redirect after the form has been submitted, please have a look at the following piece of code (for version >= 3.9):
add_action( 'wpcf7_before_send_mail', wpcf7_disablEmailAndRedirect );
function wpcf7_disablEmailAndRedirect( $cf7 ) {
// get the contact form object
$wpcf7 = WPCF7_ContactForm::get_current();
// do not send the email
$wpcf7->skip_mail = true;
// redirect after the form has been submitted
$wpcf7->set_properties( array(
'additional_settings' => "on_sent_ok: \"location.replace('http://example.com//');\"",
) );
}
Hook into wpcf7_before_send_mail instead of using the flag .
add_action("wpcf7_before_send_mail", "wpcf7_disablemail");
function wpcf7_disablemail(&$wpcf7_data) {
// this is just to show you $wpcf7_data and see all the stored data ..!
var_dump($wpcf7_data); // disable this line
// If you want to skip mailing the data..
$wpcf7_data->skip_mail = true;
}
Just an update. The following works in 4.1.1.
on_sent_ok: "location = 'http://domain.com/about-us/';"
demo_mode: on
Set skip_mail: on does the trick.
There might have been a change to contact-form-7, because I wasn't able to access the $skip_mail variable in the WPCF7_Submission object. I looked at the submission.php object in the \wp-content\plugins\contact-form-7\includes\submission.php file and found this:
private $skip_mail = false;
Since the variable is private, and there are no getters or setters in the file, you're not going to be able to change it externally. Just change it to this:
public $skip_mail = false;
and then you can change the variable like this in your functions.php file:
add_filter('wpcf7_before_send_mail', 'wpcf7_custom_form_action_url');
function wpcf7_custom_form_action_url( $form)
{
$submission = WPCF7_Submission::get_instance();
$submission->skip_mail = true;
}
A reminder, if you update the contact-form-7 plugin, it will probably nullify your change, so keep that in mind.
Simple code
Copy and paste the following code in your activated theme functions.php file.
add_filter('wpcf7_skip_mail','__return_true');
UPDATE WPCF7 ver. 7.5: There is now a filter specifically to handle this.
function my_skip_mail($f){
$submission = WPCF7_Submission::get_instance();
$data = $submission->get_posted_data();
if (/* do your testing here*/){
return true; // DO NOT SEND E-MAIL
}
}
add_filter('wpcf7_skip_mail','my_skip_mail');

exit function if error - cakephp

I have a function to check if a credit card is valid or not. If it is then continue to enter the details from the form into the database. But if it is not then display the message that is passed.
The problem is that if there is an issue with the credit card the message is passed but the rather then exiting the function so that it does not try to continue and add the data from the form, it adds the data.
I am not sure how to stop. The following code was written for me, seems to create a new dispatch and try to go back to the previous function confirm.
function confirm() {
//This view contains the form, when user submits they go to checkout view
if (isset($data)){$this->data = $data;}
$this->set('redirect_to', 'checkout');
}
function checkout(){
if(!empty($this->data['User']['card_number'])){
$check_card = $this->BillingValidation->validate_card($this->data['User']['card_number']);
if($check_card['valid']!=false){
// card is valid !
} else {
$msg[0][] = $check_card['error'];
$flashmsg = implode('<br />',$msg[0]).implode('<br />',$msg[1]);
$this->Session->setFlash(__($flashmsg,
true),'default', array('class' => 'flash-message-success'));
//if credit card is invalid go back to confirm view
$this->autoRender = false;
$d = new Dispatcher();
$d->dispatch(array("controller" => "res", "action" => "confirm"),array("data" => $this->data));
}
}
//if credit card ok then continues to process form
}
I used exit() and that seemed to work

Categories