wp_mail doen't send mails whit attachment

On my site I hava two forms witch send email. The one whit no attachment needed is sent correnctly, but the other ony witch has an attachment does not get sent. I am using SMTP config whit Postman SMTP plugin. move_uploaded_file($_FILES["cv"]["tmp_name"],WP_CONTENT_DIR .'/uploads/CV/'.basename($_FILES['cv']['name'])); move_uploaded_file($_FILES["lm"]["tmp_name"],WP_CONTENT_DIR .'/uploads/lm/'.basename($_FILES['lm']['name'])); $attachments = array( WP_CONTENT_DIR ."/uploads/CV/".$_FILES["cv"]["name"], WP_CONTENT_DIR ."/uploads/lm/".$_FILES["lm"]["name"] ); this is the code I use for storeing and reaching the attachments and simpli useing the wp_mail function to send it like this: $sent=wp_mail($s, $subject, $message, $headers,$attachments); On …
Category: Web

Generate and send ICS file through WordPress

I'm writing a custom plugin for reservations. I need to generate an .ics file that needs to be sent to a predefined email address. I've tried some library like ZContent iCalendar and a PHP script that I found on github that I've included inside my plugin code. The script works well and I can obtain a valid output. The problem is I can't figure out how to generate the ics file and attach it to an email using the wp_mail …
Category: Web

How to send email with wp_mail() with from email taken from contact form instead of the host?

I have set up SMTL like this, add_action( "phpmailer_init", "send_smtp_email" ); function send_smtp_email( $phpmailer ) { ini_set("sendmail_from","[email protected]"); ini_set("sendmail_path","[email protected]"); // Define that we are sending with SMTP $phpmailer->isSMTP(); // The hostname of the mail server $phpmailer->Host = "localhost"; // Use SMTP authentication (true|false) $phpmailer->SMTPAuth = false; // SMTP port number - likely to be 25, 465 or 587 $phpmailer->Port = "25"; // Encryption system to use - ssl or tls $phpmailer->SMTPSecure = "tls"; $phpmailer->From = "[email protected]"; $phpmailer->FromName = "XYZ"; } and …
Category: Web

Filter wp_mail based on content type

I can current filter the content type of the wp_mail function: add_filter( 'wp_mail_content_type', function( $content_type ) { return 'text/html'; }); And I can filter the message content add_filter( 'wp_mail', function( $args ) { $args['message'] = 'Filtered text here'; return $args; }); But how can I only do the latter conditionally? I only want to filter the message when the content type == text/plain. I'm guessing there is a super-simple solution to this, but I haven't worked it out yet.
Category: Web

wp_mail() not sending emails with ajax

I am using wp_mail() to send email using ajax. My mail code is as follow. add_action( 'wp_ajax_send_confirmation_email', 'wpse_sendmail' ); add_action( 'wp_ajax_nopriv_send_confirmation_email', 'wpse_sendmail' ); function wpse_sendmail() { if(isset($_GET['is_email']) && $_GET['is_email'] == true){ $temp_dir = get_template_directory_uri(); $url = $temp_dir."/confirm_email.php?id=".$_REQUEST['id']."&key=".$_REQUEST['key']; $message = "Username:".$_REQUEST['name']."Click on below link to confirm your email;".$url; $subject = "Email confirmation Link"; $headers = "From: [email protected]" . "\r\n"; if ( wp_mail( $_REQUEST['email'], $subject, $message, $headers ) ) { echo "1"; } else { echo "0"; } } } And AJAX …
Category: Web

Send specific users an email when posts are published

I've got the following code, which is supposed to run when a new post is published for the first time, check if a custom field 'specific_users' has data (this uses Advanced Custom Fields), and if so, send an email to each of the selected users. /** * Send users a notification of new grower posts */ function notify_growers($post) { // Only notify for grower posts if ( $post->post_type != 'grower_posts' ) return; $post_id = $post->ID; // ...run code once if …
Category: Web

wp_mail() inside AJAX handler never returns

We have an AJAX handler called by jQuery.ajax() that takes a document stored on the server and mails it to the user. At the bottom there is a call to wp_mail like so: $status_wpmail = wp_mail($recipient, $subject, $body, $headers, $filename); Problem is the email never gets sent out, and any code after the wp_mail call never gets parsed, including a debug statement to dump out the value of $status_wpmail. The jqXHR response sent back to the page reports 'success' however. …
Category: Web

How to send the checkbox value to email

HTML of form is given below <?php for($i=$start;$i < $end ;++$i) { if($emails[$i]!=""){ $userId=$emails[$i]['ID']; $user_info = get_users($userId); echo"<tr class='iedit alternate'> <td class='name column-name' style='border:1px solid #DBDBDB;padding-left:13px;'><input type='checkbox' id='haet_mail_test_address' name='ckboxs[]' value='".$emails[$i]['user_email']."'> ".$emails[$i]['user_email']."</td>"; echo "<td class='name column-name' style='border:1px solid #DBDBDB;'> ".$user_info->user_login."</td>"; echo "</tr>"; } } ?> <button class="button-primary" id="haet_mail_test_submit" name="submit" type="submit">Send Email</button> <div id="haet_mail_test_sent" class="haet-mail-dialog" title="<?php _e('Email sent','wp-html-mail'); ?>"> <p> <?php _e('Your message has been sent.','wp-html-mail'); ?> </p> below my Javascript code $('#haet_mail_test_submit').click(function(){ var checkbox = $('#haet_mail_test_address').val(); $.post(ajaxurl, { 'action':'haet_mail_send_test', 'checkbox':checkbox} , function(response) …
Category: Web

Get page permalink in contact form

<?php function leverage_handle_ajax_request() { if ( ! empty( $_POST ) ) { require_once( plugin_dir_path( __FILE__ ) . 'recaptcha.php' ); if ( isset( $_POST['section'] ) && $_POST['section'] == 'leverage_form' ) { $source = 'Contact Form'; $field_send_options = 'form_sending_options'; $field_recipient = 'form_email_recipient'; $field_webhook_url = 'form_webhook_url'; $wpnonce = 'leverage_form_wpnonce'; $subject_text = get_field( 'form_subject_message', 'option' ); $heading_text = get_field( 'form_heading_message', 'option' ); $success_text = get_field( 'form_success_message', 'option' ); $validation_text = get_field( 'form_validation_message', 'option' ); $error_text = get_field( 'form_error_message', 'option' ); } elseif ( isset( …
Category: Web

wp_mail() function doesn't send email in Ajax mode

When I use the wp_mail() or mail() function in AJAX, the function doesn't work and doesn't send email. When I use these functions simply in my functions.php file it works fine. It's not related to WordPress functions or actions. I have checked everything, including using SMTP mail. SMTP mail works same as mail() function and it doesn't send in AJAX mode. This is my functions.php file content: add_action( 'phpmailer_init', 'wpse8170_phpmailer_init' ); function wpse8170_phpmailer_init( PHPMailer $phpmailer ) { $phpmailer->Host = 'godadysmtpsampledomain.secureserver.net'; …
Category: Web

How to do string attachment with wp_mail

I'm using a gift card plugin for my woocommerce shop and I would like to add a generated pdf file to allow customers to download the gift card as a pdf. The idea is to use TCpdf or Fpdf to generate the pdf and output it as a string. // Close and output PDF document // This method has several options, check the source code documentation for more information. echo $pdf->Output('S'); The problem is to get this file as an …
Category: Web

Send email button in custom post type backend

I've added a button in the backend of my custom post type editor. I want to send an email using wp_mail() when admin user click a button. I've added this custom form and button to a meta box. See screenshot. The problem is that when clicking this button Wordpress redirects to the default backend posts list page (https://mysite.test/wp-admin/edit.php). I am making use of the do_action( "admin_post_{$action}" ) hook. When I inspect the page I see Wordpress has removed the tags. …
Category: Web

How to disable wp_mail for all users except for admins?

I am using the following code to disable wp_mail however how do I disable it only for non-admins. Any user with admin privileges should still receive their emails. add_filter('wp_mail','disabling_emails', 10,1); function disabling_emails( $args ){ unset ( $args['to'] ); return $args; }
Category: Web

Custom user registration fields in user_register hook

I am trying to send an email to administrator with user_register action hook and wp_mail() function when a new user registers. I created some custom registration fields and I want send them via e-mail, but I cannot access them via the get_user_meta() function. I tried to debug this in front-page and using this get_user_meta() function gets me my custom fields, but in functions.php in my custom function, fields are missing and I get only few fields: (nickname,first_name,last_name,description,rich_editing,syntax_highlighting,comment_shortcuts,admin_color,use_ssl,show_admin_bar_front,locale,wp_capabilities,wp_user_level) add_action( 'user_register', 'so27450945_user_register', …
Category: Web

Email reply to multiple email addresses not working

I want that email reply should be received at multiple email address. But it is not working for me. I have tried different ways but none of these working for me. I am trying this header but it is only replying to the last email address. $to = "[email protected]"; $subject = "my email subject"; $message = "my email message"; $headers = array(); $headers []= "MIME-Version: 1.0\r\n"; $headers []= "Content-Type: text/html; charset=UTF-8\r\n"; $headers []= "Reply-To: <" . $EmailAddress1 . "> <" …
Category: Web

wp_mail send multiple emails in a loop

I'm very confused with wp_mail(). Here my code. function email_notification_for_admin_and_customer( $order_data ) { $subject_email = 'Subject LOREM IPSUM'; $customer_email = 'Hi Customer, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus, dui eget luctus accumsan, turpis orci malesuada turpis, eget volutpat ante velit a quam.'; $admin_email = 'Hi Admin, Lorem ipsum dolor sit amet, consectetur adipiscing elit. Quisque tempus, dui eget luctus accumsan, turpis orci malesuada turpis, eget volutpat ante velit a quam.'; $send_email = array( array( 'to' => …
Category: Web

How to send bulk messages using wp mail function?

I was working in custom plugin development. I have created customer table in woocommerce and create form to reminder customer for new offers. I am using wp mail function to send multiple email to customer but its works with single customer mail. here its my code <form class="formpopup" action="#" method="post"> <div> <label>To</label><input id="customer_to_mail" type="text" class="modalform" style="width: 70%;" value="" name="customer_to_mail" required></div><br> <div><label>Subject</label><input class="modalform" style="width: 70%;" type="text" name="customer_subject" required></div><br> <div class="descr"><label>Description</label><textarea class="modalform" style="width: 70%; height: 150px;" name="customer_description" required></textarea></div><br> <input style="margin: 20px auto; …
Category: Web

wp_mail() not sending email in multisite subdomain

I have a multisite enabled WordPress configuration. My main domain is like http://www.example.com, with several subdomains like http://test1.example.com, http://test2.example.com, and so on. I have written a function in my multisite theme's function file to send some notifications to the multisite users. $headers[] = 'Content-Type: text/html; charset=UTF-8'; wp_mail('[email protected]', 'Test','Test', $headers); It send the mails as desired when on the main domain, but it does not send any mails when used in subdomain function files. For example, [email protected] is a registered user …
Category: Web

How to disable activation email to specific user role?

I'm using Ultimate Member to manage my user roles. I have the Activation Emails active and it sends to new subscribers as expected. But when a user with role "Employee" subscribes, I don't want them to get this activation email. Right now someone with the role "Employee" is getting two emails, the one I want and the extra activation one. Is there a way to deactivate the activation email for a specific user role? Thanks in advance!
Category: Web

About

Geeks Mental is a community that publishes articles and tutorials about Web, Android, Data Science, new techniques and Linux security.