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?