How to use ‘phpmailer_init’ SMTP settings only on certain ‘wp_mail’ actions?

phpmailer_init will always fire for every wp_mail() call – however, you can hook/unhook it conditionally like so: function wpse_224496_phpmailer_init( $phpmailer ) { // SMTP setup // Always remove self at the end remove_action( ‘phpmailer_init’, __function__ ); } function wpse_224496_wp_mail( $mail ) { // Example: only SMTP for emails addressed to [email protected] if ( $mail[‘to’] === … Read more

Intercepting wp_mail() to view contents

The first link on Google is to https://developer.wordpress.org/reference/functions/wp_mail/ which says that wp_mail is in wp-includes/pluggable.php It also has the full function source code showing that the first active line of the function is: $atts = apply_filters( ‘wp_mail’, compact( ‘to’, ‘subject’, ‘message’, ‘headers’, ‘attachments’ ) ); … which suggests that if you hook into the filter … Read more

WordPress is executing URL in code when called via wp_mail()

Please try the following, I think having a return from the site_url() function could be creating a problem with the $confirm_url variable. That and you have an unescaped slash in your url. $site_url = site_url(); $confirm_url = $site_url. ‘\/verification?id=’ . $post_id . ‘&hash=” . $hash; // Send a verification e-mail to the user to confirm … Read more

Change email from and display name with a filter action

A couple possibilities. Use the settings API to add a form field somewhere in your admin area where the user can enter the email they want to use. Retrieve it in your hooked function with get_option. This would be the way to go if you’re going to use the same from email everywhere. <?php add_filter(‘wp_mail_from’, … Read more

If new comment posted in custom post – send notification to custom email from custom field

You can try something like this in your functions.php function send_comment_email_notification( $comment_ID, $commentdata ) { $comment = get_comment( $comment_id ); $postid = $comment->comment_post_ID; $master_email = get_post_meta( $postid, ‘master_email’, true); if( isset( $master_email ) && is_email( $master_email ) ) { $message=”New comment on <a href=”” . get_permalink( $postid ) . ‘”>’ . get_the_title( $postid ) . … Read more

wp_mail() is not working in localhost

wp_mail() falls back to php’s mail() function which requires a configured MTA (Message Transfer Agent) on your host. So either you install and configure such a MTA. If you’re running a Linux like OS, SSMTP is an easy solution on which you can use any mail-provider to send your system mails via SMTP. Another MTA … Read more

Should I use wp_mail or PHP’s mail? [duplicate]

WordPress offers its own mailing system. I suggest you use that instead of PHP’s native mail. wp_mail accepts five arguments: wp_mail( $to, $subject, $message, $headers, $attachments ); So your code can be written this way: // Set the headers $headers[] = ‘From: ‘ . get_option(‘admin_email’); // Add the addresses to an array foreach($emails as $mail) … Read more

How to allow specific extensions and file size to wp_mail attachment?

Add the following condition before the file upload functionality – $allowedExts = array(“pdf”, “jpg”, “png”); $temp = explode(“.”, $_FILES[“attachment”][“name”]); $extension = end($temp); if ((($_FILES[“file”][“type”] == “image/pdf”) || ($_FILES[“file”][“type”] == “image/jpg”) || ($_FILES[“file”][“type”] == “image/png”)) && ($_FILES[“file”][“size”] < 1000000) && in_array($extension, $allowedExts)) { //your file upload code and other stuffs } else { echo “Invalid file”; … Read more

How to Configure SMTP on wordpress Cant Send Email

You didn’t say what the problem is. You certainly should be able to send email using PHP mail or plugins from wordpress. Is it a security problem? Your password being rejected at authentication? Try using OAuth 2.0. https://wordpress.org/plugins/postman-smtp/ Is it a firewall problem? Are all the SMTP ports blocked? Try sending with an HTTPS API … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)