Wordpress Php auto email to comment author - wordpress

I'd love to be able to automatically send a response to the person who comments on a post on my site. Their email is required so I feel as though I should be able to grab that and use php to send an email back to that email address...
I know the basics for a php email go as follows... So I just need help grabbing the authors email and putting it into the mailTo variable
<?php
$subject = 'My subject';
$message = "The Message I'd like to send back to the commenter";
$mailTo = get_comment_author_email_link
mail($mailTo, $subject, $message);
?>
Thanks!

I think what you need is to hook to the comment post action with your defined own function as such:
<?php
function sendMail($id){
$subject = 'My subject';
$message = "The Message I'd like to send back to the commenter";
$comment=get_comment($id);
$mailTo = $comment->comment_author_email ;
mail($mailTo, $subject, $message);
}
add_action('comment_post', 'sendMail');
?>

you can use this , but dont forget the comment of webarto :
http://wordpress.org/extend/plugins/wp-comment-auto-responder/

Related

Sending mail to thousands of customers at a time ( wp_mail -Wordpress)

I want to send a total of 1650 mails on Christmas eve from a WordPress website.
This is my current code:
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type: text/html; charset=" . get_bloginfo('charset') . "" . "\r\n";
$customers = get_users($args);
$cus_arr = array();
foreach($customers as $customer){
array_push($cus_arr,$customer->data->user_email);
}
wp_mail($cus_arr, $subject, $message, $headers);
/*another way*/
...
foreach($customers as $customer){
wp_mail($customer->data->user_email, $subject, $message, $headers);
}
Question 1 : Is the above way a good choice for sending a mail to this amount of customers? May there be any problem? Is there any better way of doing it?
Also I dont want customers to see each others mail. This is my current code:
wp_mail(array("BCC: xyz#xyz.com","BCC: abc#abc.com"), $subject, $message, $headers);
But it does not work. Without BCC: the mails are actually sent.
Question 2. How can I prevent users from seeing other mail ids?
Question 1: It's good practice to use a rate limit(throttling), e.g. max 100 mails/10 minutes. You can do this by storing the recipients in a database, and use a cronjob to send mail every 10 minutes. Another option is to use a 3rd party mail service, such as Mandrill or Sendgrid, they'll handle throttling for you.
Question 2: Your current code calls wp_mail for each recipient, so they'll never see other mail addresses (no need for BCC headers). However if you decide to use wp_mail to send to multiple recipients in 1 call, you need to use bcc headers, e.g.:
wp_mail('', $subject, $message, array("BCC: xyz#xyz.com","BCC: abc#abc.com"));
Hey there I think your code is a bad idea because of the following reasons:
The script may exceed the max execution time or the memory limit of the server
it may work, but wp_mail is just not a good solution for sending this huge amount of emails
What I would recommend is to use a library for sending bulk e-mails. There are existing WordPress Plugins for this purpose however you can easily do it yourself - here is my solution with the classic, well tested PHPMailerLibrary (https://github.com/PHPMailer/PHPMailer):
In your functions.php:
require("libs/phpmailer/PHPMailerAutoload.php");
/**
#param $from: The senders E-Mail
#param $from_name: The senders Name
#param $subject: The E-Mail subject
#param $mesesage: The E-Mail content HTML
#param $to: An array of receivers
*/
function my_custom_send_mass_mail($from,$from_name,$subject,$message,$to) {
// first use PHPMailer to send all the emails
$email = new PHPMailer();
$email->isSMTP();
$email->CharSet = 'utf-8';
$email->From = $from;
$email->FromName = $from_name;
$email->Subject = $subject;
$email->Body = $message;
$email->IsHTML();
if(is_array($to)) {
foreach($to as $t) {
$email->addBCC($t);
}
}
$ac = time();
update_option('mailsent-'.$ac,$email);
$success = $email->send();
if($success) {
update_option('mailsent-suc-'.$ac,"yes");
return "Bulk E-Mail successfully sent.";
}
update_option('mailsent-suc-'.$ac,$email->ErrorInfo);
return "Bulk E-Mail Error: Please contact admin.";
}
Just call this function and make sure $to is the array of receiver e-mails.
This is the solution I am using for a customer sending a 10000 E-Mail newsletter weekly and it works great so far.

Buddypress - activation link not sent to user's email address

I recently installed buddypress in my wordpress.
When a person registers on my website using registration form
a message appears saying that an activation link has been sent to the email address you provided, but user receives no email.
Please tell me to solve this.
is there any problem in wp_mail or do I need to config
something in my hosting file manager?
First , test the wp_mail function with the following code by creating wp-test.php in root folder.
include 'wp-load.php';
$to = 'example#example.com';
$subject = 'The subject';
$body = 'The email body content';
$headers = array('Content-Type: text/html; charset=UTF-8');
wp_mail($to, $subject, $body, $headers);
After that if it's still not working , you need to install and configure Easy WP SMTP and setup the SMTP settings from your host.

How to access the response/redirect after stripe payment?

Im trying to sell videos on my website, hosted using wordpress. I have set up a Stripe account and been using "WP Simple Pay Lite for Stripe" Plugin on my website.
The problem that i'm facing is when I get a payment on stripe I manually send my customers the video that they have purchased. I was wondering if anyone has any advice on how I can automate the process by sending my customers the product once payment has been paid.
For this "WP Simple Pay Lite for Stripe" Plugin there is a successful payment URL redirect feature. That I was using before. How ever I noticed that you can view the successful payment redirect from the Developer Tools.
<input type="hidden" name="sc-redirect" value="https://wpsimplepay.com/demo-success-page/">
In this topic which is similar to yours the author suggests to use sc_after_charge hook. So your code will be:
add_action( 'sc_after_charge', 'sc_after_charge_example' );
function sc_after_charge_example( $charge_response ) {
if ( $charge_response->paid ) {
$url = 'https://wpsimplepay.com/demo-success-page/';
wp_redirect( $url );
exit;
}
}
I am not sure abou the response type and if its JSON, but in Stripe Docs it's a JSON.
As Stanimir Stoyanov said, you can use sc_after_charge but his code won't work because sc_after_charge returns Charge object, not JSON.
/**
* Sends video url to customer when payment is successful
* #param $response \Stripe\Charge
*/
function send_video_if_payment_successful( $response ) {
if ( $response->paid ) {
// Maybe check amount and or description to ensure it's same product
$file = 'http://url_to/file_to_attach.mp4'; // Video url
$subject = 'Find your video here - My store'; // Email subject
$msg = '
Thanks for buying...
yada yada yada...
Please find attached video.'; // Email message
$attachments = array( $file ); // Add attachment
$headers = 'From: My store <myname#example.com>' . "\r\n"; // Set yourself in From header
wp_mail( $response->receipt_email, $subject, $msg, $headers, $attachments ); // Send the mail
}
}
add_action( 'sc_after_charge', 'send_video_if_payment_successful' );
Here we first check if payment was successful, if yes, we the email the file to the user :)
If you plan to sell multiple products... You can set appropriate description and send different files for different descriptions accessible by $response->description
In the short code add success_redirect_url="https://wpsimplepay.com/demo-success-page" as an attribute
[stripe name="My Store" description="My Product" amount="1999" success_redirect_url="https://wpsimplepay.com/demo-success-page"]
Source: https://wpsimplepay.com/docs/shortcodes/stripe-checkout/
please use woocommerce download product
https://docs.woocommerce.com/document/digitaldownloadable-product-handling/
check this i hope it is helpfull

wp_mail_from: different from address each time

I have a form. Where user gives their name and email address. The I use the custom plugin to send the mail. The requirement is I need to send the mail on behalf of the user who signed.
Now in wp_mail how to achieve that?
I know about this filter: wp_mail_from. But how to call it every time wp_mail is called and set different from address?
Finally I also want to clear the wp_mail_from filter so that it doesn't affect the other forms.
Thanks,
wp_mail accepts "headers"
http://codex.wordpress.org/Function_Reference/wp_mail#Using_.24headers_To_Set_.22From:.22.2C_.22Cc:.22_and_.22Bcc:.22_Parameters
<?php
$headers = 'From: My Name <myname#example.com>' . "\r\n";
wp_mail('test#example.org', 'subject', 'message', $headers );
?>

sending a mail with Drupal's user_save

I have a website that has to insert users in a Drupal database. I include the Drupal bootstrap file and call the user_save() function.
The paramenters I pass to user_save are: the first one a stdClass with property 'status'=1, and the second parameter is (what's expected to be sent, because the insert works just fine).
The problem I'm having is that the user receives no confirmation email. I think user_save should send the user an email, but it doesn't. Maybe I'm missing something here, so your help is much appreciated!
The second paramater should be an array:
user_save($account, array('status' => 1));
You can always look at http://api.drupal.org/api/drupal/modules%21user%21user.module/function/user_save/6 to understand the user_save function in detail..
Just to make sure, you have checked the settings for sending email on registration?
admin/config/people/accounts
Sometimes there are problem with email on crappy servers/some hosts are limiting the php mail function. Here is a simple php mail call you could try if you're not sure if the mail-function runs without problem on your server.
<?php
$to = 'youremail#yourhost.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: youremail#yourhost.com' . "\r\n" . 'Reply-To: youremail#yourhost.com' . "\r\n" . 'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
?>

Resources