1

Here i have created one checkbox in admin of the wordpress and when i check and update it send mail to user it works but its sends mail every time when any part of profile is updated.Is there a way to send mail only once?

Also here i have list of property when user request for any it shows entry in backend and when admin approves it should sent email for every pdf approval by user.so when admin approves any pdf it notifies user.But at this moment it does not happen.it fires email every time when i update profile.

add_action( 'show_user_profile', 'add_extra_profile' );
add_action( 'edit_user_profile', 'add_extra_profile' );
function add_extra_profile(){
 global $pagenow;       
    if($pagenow == 'profile.php'){
       $us_id = get_current_user_id();
    }
    else{
     $us_id = $_GET['user_id'];
    }

$deal_meta = get_user_meta($us_id, '_userdeal'); 
$boro_meta = get_user_meta($us_id, '_borrowerdata');
$boro_status = get_user_meta($us_id, '_userformstatus');
$termsheet_meta = get_user_meta($us_id, '_usertermsheet');
$approve_termsheet_meta= get_user_meta($us_id, '_approvaltermsheet');  



$get_boro =unserialize(base64_decode($boro_meta[0]));
/*----------Termsheet Form------------------*/
$expd= explode(",",$termsheet_meta[0]);

if(!empty($termsheet_meta[0])){
echo "<table border='1' >";    
echo "<tbody><tr><th style='padding:10px;'><label>List Of Termsheet Applied For</label></th>
                <th style='padding:10px;'><label>Approval<label></th>    
            </tr>";
echo "<tr>";
for($i=0;$i<count($expd);$i++):
 $post_d = get_post($expd[$i]); 
 $title = $post_d->post_title;


echo "<td style='padding:10px;'><a href=".get_permalink($expd[$i] ).">".$title."</a></td>
        <td style='padding:10px;' >";
    if(!empty($approve_termsheet_meta[0]) &&in_array($expd[$i],$approve_termsheet_meta[0])){ 
    echo "<input type='checkbox'  name='approve_termsheet[]' value=".$expd[$i]."  checked />";
    }
    else{
     echo "<input type='checkbox'  name='approve_termsheet[]' value=".$expd[$i]."  />";
    }
echo "</td>";
    if( $i % 1== 0 ) {
    echo "</tr><tr>";
  }   

endfor;

echo "</tr>";
echo "</tbody>";    
echo "</table>";

//print_r($_REQUEST['approve_termsheet']);  
$user_info = get_userdata($us_id );
$subject = 'User Approval';
$to=$user_info->user_email;    
$body = "Your Property Termsheet is Appoved For Download.</br> You Can Login And Download It" ;
add_filter('wp_mail_content_type',create_function('', 'return "text/html"; '));

$mailSent = get_user_meta($us_id, 'mail_sent', true);

if($mailSent){
    update_user_meta($us_id, 'mail_sent', 'mail sent');
}else{
    $borrower_mail=wp_mail($to, $subject, $body);
}    


}
  • You can add user_meta first time when you send the mail and check if the user_meta is exist for that user then skip mail sending functionality – Mitul Jun 19 '15 at 13:08
1

Please add following condition.

$mailSent = get_user_meta($us_id, 'mail_sent', true);
if($mailSent){
    update_user_meta($us_id, 'mail_sent', 'mail sent');
}else{
    $borrower_mail=wp_mail($to, $subject, $body);
}
  • i have some list of post with checkbox and when admin check yes and save them it should notifiy the user.How its possbile? – Vishal Jun 20 '15 at 6:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.