Notification via email?

0

I have a public form on a site I'm developing but is there any way of receiving notification, via email, that someone has added some content to the site via the public form and/or the normal WP Admin way of adding site content?

asked May 17 '10 at 11:37

daretothink

11

add comment
enter at least 15 characters

21 Answers

0

I've managed to do this, sort of!

Adding the following sends an email whenever anything is submitted

<pre>mail('me@myemail.com', 'Item Uploaded', 'Something new is here');</pre>

but how do I do the following:

  1. specify what has just been uploaded
  2. specify a different "from" email address. As this is currently sent by my webhost and so it's a bit of a weird email address.

answered May 17 '10 at 11:56

daretothink

11

add comment
enter at least 15 characters
0

Arhh, that's not actually correct! The code I mentioned above is triggered whenever the page is loaded as well as whenever the submit button is clicked.

answered May 17 '10 at 12:08

daretothink

11

add comment
enter at least 15 characters
0

Ah ha, I think I've got it. Looking at this post save helper: http://podscms.org/codex/after_helpers

and this forum post: http://podscms.org/forums/bug-reports/publicform-and-helpers

The only thing I'd like help with is the message that gets sent. I've set this up as a post-save helper which gets sent to the site admin:

<pre> <?php $to = "site@sitename.com"; $subject = "A new member has joined"; $message = $columns['name']['value']; $headers = "From: Site name <site@sitename.com>\r\n\"; wp_mail( $to, $subject, $message, $headers, $attachments ); ?> </pre>

But what I'd like to add in the message field is "A new member called ['name'] has joined the site. Their email address is ['email']

Can anyone help with how I format that to work. Thanks.

answered May 17 '10 at 6:13

daretothink

11

add comment
enter at least 15 characters
0

Can somebody please guide me as to how I add content to an auto email on a publicform. I can only seem to add either plain text or a single element from the form itself. Whereas I'd like to add something like this: "A new member called ['name'] has joined the site. Their email address is ['email']

answered May 24 '10 at 5:28

daretothink

11

add comment
enter at least 15 characters
0

$message = 'A new member called '.$table_columns['name'].' has joined the site. Their email address is '.$table_columns['email'];

However, that will send everytime an item is saved. If you want to check for new items only use this to enclose the mail sending:

if (empty($params['pod_id'])) {

}

answered May 25 '10 at 7:55

jackson

33

edited May 25 '10 at 2:03

add comment
enter at least 15 characters
0

Thanks for helping but I can't seem to get either of those suggestions to work. Here's the code that I used:

<?php
if (empty($params['member'])) {
$to = "myemail@mydomain.com";
$subject = "A new member has been added";
$message = 'A new member called '.$table_columns['name'].' has joined the site.;
$headers = "From: My Domain <myemail@mydomain.com>\r\n\\";
wp_mail( $to, $subject, $message, $headers, $attachments );
}
?>

But it doesn't seem to send any emails, regardless of whether the new member already exists or not?

answered May 25 '10 at 3:44

daretothink

11

add comment
enter at least 15 characters
0

First, the if statement should be verbatim if you want to check if this is a new entry or an update.

if (empty($params['pod_id'])) {

Second, I think you have a syntax error, you're missing a closing '

$message = 'A new member called '.$table_columns['name'].' has joined the site.';

answered May 26 '10 at 7:46

jackson

33

edited May 26 '10 at 7:46

add comment
enter at least 15 characters
0

I have no idea why none of this is working but I've added the code below as a post_save helper for my "member" pod and referenced that helper in that pod. I'm not sure what 'pod_id' should be??

<?php
if (empty($params['pod_id'])) {
$to = "myemail@mydomain.com";
$subject = "A new member has been added";
$message = 'A new member called '.$table_columns['name'].' has joined the site.';
$headers = "From: My Domain <myemail@mydomain.com>\r\n\\";
wp_mail( $to, $subject, $message, $headers, $attachments );
}
?>

If I remove the if statement to test the message then this seems to add all test except the important 'name' which it just leaves blank on my final email?? I'm a little lost with all of this,=.

answered May 26 '10 at 11:18

daretothink

11

add comment
enter at least 15 characters
0

I've managed to figure out the message problem. Here's the correct code:

$message = 'A new member called '.$columns['name']['value'].' has joined the site.';

I'm still none the wiser about the checking wether the pod is already saved in order to not send out an email every time submit is clicked.

answered May 26 '10 at 11:24

daretothink

11

add comment
enter at least 15 characters
0

Please see this topic.

// Old
$table_columns['name']

//New
$columns['name']['value']

answered May 26 '10 at 11:26

logikal16

249

add comment
enter at least 15 characters
0

Can anyone help with this? Currently it's great that it's sending me an email every time somebody gets added to the site but it also does this if I go and edit somebody that's already been added. I've tried using that code that jackson suggested but it doesn't work.

answered Jun 4 '10 at 8:16

daretothink

11

add comment
enter at least 15 characters
0

Anyone???

answered Jun 16 '10 at 4:36

daretothink

11

add comment
enter at least 15 characters
0

Try adding a small pre_save helper that checks to see if "$params->pod_id" is empty or not, indicating whether the pod is newly created or not. Then attach this result as a boolean property to "$params" to check for later in your post_save helper:

<?php
$params->is_new_pod_item = empty($params->pod_id) ? true : false;
?>

answered Jun 16 '10 at 4:49

clarinetlord

456

add comment
enter at least 15 characters
0

Please forgive me here but how and where do I attach this property to "$params"?

I've added the pre-save helper to the pod that I get notified about but I'm unsure about the rest of it with regards to the post_save helper

answered Jun 17 '10 at 5:14

daretothink

11

add comment
enter at least 15 characters
0

The "$params" object is available in the post_save helper as well, so you just need an IF statement in your post_save helper:

<?php
if($params->is_new_pod_item) {
    // send mail notification
} else {
    // do something else
}
?>

answered Jun 17 '10 at 6:34

clarinetlord

456

add comment
enter at least 15 characters
0

Forgive me for being stupid but how would I then combine the statement above with the email code I'm using in the current post-save helper?

    <?php
if (empty($params['pod_id'])) {
$to = "myemail@mydomain.com";
$subject = "A new member has been added";
$message = 'A new member called '.$table_columns['name'].' has joined the site.';
$headers = "From: My Domain <myemail@mydomain.com>\r\n\\";
wp_mail( $to, $subject, $message, $headers, $attachments );
}
?>

answered Jun 25 '10 at 8:42

daretothink

11

add comment
enter at least 15 characters
0

I've added the following as a post save helper but it doesn't seem to send any emails?!

<?php
if($params->is_new_pod_item) {
$to = "myemail@mydomain.com";
$subject = "A new member has been added";
$message = 'A new member called '.$table_columns['name'].' has joined the site.';
$headers = "From: My Domain <myemail@mydomain.com>\r\n\\";
wp_mail( $to, $subject, $message, $headers, $attachments );
} else {
    // do something else
}
?>

answered Jun 28 '10 at 11:32

daretothink

11

add comment
enter at least 15 characters
0

Did you add the pre_save helper as well? This is required to define "$params->is_new_pod_item".

answered Jun 28 '10 at 12:49

clarinetlord

456

add comment
enter at least 15 characters
0

Doh, yep I had removed that - I've now added the pre-save helper and all appears to be working well. Done a number of tests and I only get notified on new website additions and not when any changes are made to the individual member.

On another note. I am using this on the confirmation email sent to the user and I thought by adding \n\n that this would then add a paragraph break but it just seems to add that text to the email instead. Here's it in the code:

$message = "Thanks for registering. We'll get back to you shortly. \n\n The Admin Team";

Any ideas how I would add a paragraph break?

By the way, thanks so much for your help with the email issue - that was really appreciated.

answered Jun 28 '10 at 3:06

daretothink

11

add comment
enter at least 15 characters
0

Hi, This thread has really helped me out thanks and ..sorry daretothink I'm not sure about the paragraph break I've tried loads of variations of \n and nothing works.

But I was just wondering if I wanted to send two different emails, one to the registrar (thanks email) and one to admin (signup email). Is it ok to just add another copy of the post save helper with different $to $subject $message etc. in it?

Thanks

answered Oct 11 '10 at 12:08

inspiration

7

add comment
enter at least 15 characters
0

about the paragraph break, here is the solution, extracted from this support forum on wordpress website: http://wordpress.org/support/topic/wp_mail_content_type

The the trick is to build a custom header with the MIME, Content Type. Without setting Content-Type wp_mail assumes plain/text. So, you have to change that, below is an example.

$headers= "MIME-Version: 1.0\n" .
    "From: Me <dale.hurley@example.com>\n" .
    "Content-Type: text/html; charset=\"" .
get_option('blog_charset') . "\"\n";
wp_mail($emailaddress, $subject, $content, $headers);

answered Nov 28 '10 at 8:29

thomasbern

1

add comment
enter at least 15 characters