Wordpress contact-form-7 plugin do something before mail - php

I have got a wordpress instance with the plugin contact-form-7. In some tutorials, I saw that I can do something before sending the mail with this code:
add_action("wpcf7_before_send_mail", "wpcf7_do_something_else");
function wpcf7_do_something_else(&$wpcf7_data) {
// Here is the variable where the data are stored!
var_dump($wpcf7_data);
// If you want to skip mailing the data, you can do it...
$wpcf7_data->skip_mail = true;
}
I got the code from here http://code.tutsplus.com/tutorials/mini-guide-to-contact-form-7--wp-25086
But somehow, it is not working. I don't receive any error - the contact form is not sending the mail anymore, even without the $wpcf7_data->skip_mail = true, and it doesn't print anything.
My questions:
Where do I have to write this code? Directly into the plugin? (At the moment, I wrote this code into a custom plugin, maybe wrong?)
Is it even possible to print any data from the form in there? (Is the tutorial bad?)
Thanks!

Well, it is normal that the contact form does not send email anymore, as it is defined on this line $wpcf7_data->skip_mail = true;.
This code is used if you want something else than the default posting (sending in email), as described in the tutorial.
This code, however, should be placed in your theme's functions.php file (if file exists, create it). But still, the email will not be send.
If you want to skip emails and perform other action, then leave this piece of code
$wpcf7_data->skip_mail = true;
and add your logic after this line.
Describe more precisely what do you want to do (instead of sending email) in your question.

Related

Using php variable from one isset to another

I have a page where on form submit from previous page a div with something like invoice is created. I send that data to server and populate the invoice for print/generate PDF etc.
if (isset($_POST['kreiraj'])) {
$emailuser = $_POST["na_email"];
}
On same page I create with JS a PDF from canvas of that invoice and send it via Ajax for posting into PHP mail script witch is also on same page.
if (isset($_POST['fileDataURI'])) {
$pdfdoc = $_POST['fileDataURI'];
};
This all works but I have problems accessing PHP variables from each other.
I have read about function global and $_GLOBLAS[varables] but nothing seems to work for me. Can someone point out a way to do it?
TO be exact i need to access $emailuser from example code above in if (isset($_POST['fileDataURI'])) php mailing script.

Preg match fails on some urls - not emails

I have the code below in the submitted form section of a php file. It is meant to catch any emails that contain a url and reject them.
if (preg_match("/(\b(((https?|ftp|file|):\/\/)|www[.])[-A-Z0-9+&##\/%?=~_|!:,.;]*[-A-Z0-9+&##\/%=~_|])/i", $msg)) {
return false;
}
return true;
But I received an email with dozens of lines like this:
[url=http://example.рф]шкафы купе[/url]
I tried sending a message with one of the lines in the original email and the code blocked it. Why didn't it stop this spammer?
Based on the replies, which I deeply appreciate, I changed the code to the following. All I really want is to block url's. It doesn't matter what the path and parameters are so I think this catches all possibilities. This is used instead of php filters because the filters page says it can't catch URN's.
if (preg_match("/(\b(((https?|ftp|file|[-A-Z0-9]|):\/\/)|www[.]))/i", $msg)) {

In OctoberCMS how do you find the hint path?

Mail::sendTo($to, 'OctoberCMS.PhotoElegance::mail.contactform', $params);
When this line of code is called I get back an error which says the following:
"No hint path defined for [OctoberCMS.PhotoeElgance] on line 112 of vendor\laravel\framework\src\Illuminate\View\FileViewFinder.php"
In simple, I am trying to send mail when the contact form is submitted. The code is inside a function called onStart(). I discovered that the appname is OctoberCMS. After the dot I have PhotoElegance as that is the website name.
After the hint path (OctoberCMS.PhotoElegance) I am calling the static function (mail.contactform) to my defined contact form which has been built in the CMS.
Where do I find out the appname and website name. How do I define these if I want to change them. I understand this is to do with name spacing but I cannot figure it out.
hi the way you try to send an email is called "Mail view" this is the way you do send mail form a plugin, and the path to the mail view is author.plugin::path.to.view.
From the very short definition of your problem i can tell that you are not using plugin but the dynamic pages feature of october cms so you must use "mail template" .
Go to setting > find mail->mail template in the left side bar > click new template chose a code once done you can use this tempalte to send email from dynamic page.
Mail::sendTo($to, 'template.code', $params);

CIVICRM 3.4 Drupal 6 custom token is not inserted in automatic mailing but in manual it is

Like in the title. I have a problem with my own custom token implemented via hook_civicrm_tokens and also hook_civicrm_tokenValues. When I try to send an email manualy, the token appears correctly in the list and it also appers parsed in the mail that the client recevies, the same with message templates expect that it appears as not parsed like {mycat.token}. It puzzles me because other tokens are inserted correctly in any case.
The code I've implemented looks something like this
function modulname_civicrm_tokens(&$tokens){
$tokens['mytoken'] = array('mytoken.something' => 'token name');
}
function modulename_civicrm_tokenValues(&$values, $contactIDs){
// some fancy logic for extracting data
foreach ($contactIDs as $cid){
$values[$cid]['mytoken.something'] = 'some data from other function connected with cid';
}
}
Sorry if I messed up the code block.
Have enyone encountered this thing? Any tips how to fix this?
Ok, I found out why this did not work. Somebody did a hack in a module that only used the template body from civicrm and send the message via mimemail so no wonder that it did not work .

MODX not sending emails

I'm using modMail class to send custom emails. I have followed the guidelines on MODX site and used the following code which I placed in a snippet:
$message = $modx->getChunk('myEmailTemplate');
$modx->getService('mail', 'mail.modPHPMailer');
$modx->mail->set(modMail::MAIL_BODY,$message);
$modx->mail->set(modMail::MAIL_FROM,'me#example.org');
$modx->mail->set(modMail::MAIL_FROM_NAME,'Johnny Tester');
$modx->mail->set(modMail::MAIL_SUBJECT,'Check out my new email template!');
$modx->mail->address('to','user#example.com');
$modx->mail->address('reply-to','me#xexample.org');
$modx->mail->setHTML(true);
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}
$modx->mail->reset();
The snippet has been modified to contain message from custom chunk as well as email addresses have been replaced with the correct ones. The snippet sent email once and never again. I have no idea what causes such behavior which prevents it from sending emails.
I have read that using the reset function $modx->mail->reset(); resets email fields and allows the email to be sent again yet I have a feeling that it causes problem here.
The snippet is called uncached on the page [[!email]]
Does anyone have an idea why the emails are not being sent, even though it worked once?
if there is an error in your chunk or in processing your chunk, modx is never going to get to thepoint where it logs an error. try something like:
if (!$modx->mail->send()) {
$modx->log(modX::LOG_LEVEL_ERROR,'An error occurred while trying to send the email: '.$modx->mail->mailer->ErrorInfo);
}else{
$modx->log(modX::LOG_LEVEL_ERROR,'This mail was sent: '.$message);
}
to see if it logs something. but otherwise what you have there is exactly correct - try to take the $message variable out and send just a string. if it sent mail once, then something else must be wrong. I'd start looking at mail server logs, headers, spam [gmail??] etc.

Categories