Quantcast
Channel: WordPress.org Forums » [WP Mail SMTP by WPForms - The Most Popular SMTP and Email Log Plugin] Support
Viewing all articles
Browse latest Browse all 5026

setting from email address in wp_mail always gets overridden

$
0
0

Replies: 0

Hi,

I’ve setup the plugin using Gmail as the mailer. I have all the correct credentials in place and also, can send out a test email successfully.

My use-case is such as described:
– The public contact form is filled by users with their name and email address and their query.
– I want to use their name and email address in the from_name, from, and reply-to fields of the mail sent out to my email_address.

I have added the following code in my theme’s functions.php

add_action('wp_ajax_sendMail', 'custom_sendmail');
add_action('wp_ajax_nopriv_sendMail', 'custom_sendmail');
function custom_sendmail(){
  if (isset($_POST['message'])){
        $to = $_POST['to_mail'];
        $subject = $_POST['subject'];

        $headers = array(
                'From: ' . $_POST['from_email'],
                'Reply-To: <"' . $_POST['from_email']  . '">',
                'Content-Type: text/html; charset=UTF-8'
        );
        $mail = wp_mail($to, $subject, $_POST['message'], $headers);
        if($mail){
                echo 'success';
        }else{
                echo 'failed';
        }

        die();
  }
  return;
}

The issue is that the from/reply-to field in the email is always set to the one I have setup in the From Email field in WP Mail SMTP settings on my admin dashboard. The same is the case with the from name field.
Please note that I do not have the Force From Email and Force From Name checkboxes selected in my settings.

What am I doing wrong?


Viewing all articles
Browse latest Browse all 5026

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>