Wordpress doesn't work properly with non standard domain names - PHPMailer fails when initialising

While debugging Wordpress password reset functionality in a test environment on a local macbook, Wordpress would get stuck when sending emails. Basically, before sending emails, a check is done in wp-includes/pluggable.php on sender email address, subject, etc, and further debugging showed that Wordpress is failing on line 408 (in version 5.8.2) $phpmailer->setFrom( $from_email, $from_name, false ); Ironically, this built-in check is performed before my custom action would correctly set the parameters: add_action( 'phpmailer_init', 'my_phpmailer_example',5 ); function my_phpmailer_example( $phpmailer ) { …
Category: Web

No longer able to attach S3 bucket files to emails being sent by WordPress due to PHPMailer security update

I've been trying to track down why my s3 bucket files are no longer being attached to automated emails being sent out by WordPress (using the Gravity Forms Entry Automation plugin). I've been able to identify the latest version of PHPMailer being the reason why the attachments no longer get added. From the PHPMailer ticket response: This is due to a bug fix that also closed a major security hole. PHPMailer deliberately avoids being a client for HTTP or other …
Category: Web

How Can I Change Default Reply ToEmail

I want to set the SMTP settings manually instead of using a plugin. I did this using this resource. However, there is a problem. If the user clicks "Reply", a different e-mail appears. Probably I've described this before with the plugin. However, I cannot remove it. If I make a new definition as below, it creates a new reply e-mail. Therefore, the past is not erased. What I want: If the user clicks to reply to the incoming e-mail, only …
Category: Web

Wordpress wp_mail function crashing website

So i've been trying to send email from my functions.php script. When wp_mail function is fired, my entire website crashes. I have enabled all the error display settings in wp-config. I literally copied and pasted the function directly from wordpress.org website, but still my email function causes crash. function send_email(){ $from = "Admin <[email protected]>"; $to = "[email protected]"; $subject = "Lamza Activation"; $message = 'Testing 1 2 3'; $headers[] = "From:" . $from . PHP_EOL; $headers[] = array('Content-Type: text/html; charset=UTF-8'); wp_mail($to, …
Category: Web

wp_mail not sending email on custom function

I have updated my wordpress to the new 5.7 version, I have a function in my functions.php file to send an email. The thing is, i have used this function before and it all worked well. Now after upgrading, i am unable send email from my custom function send_email() Custom email function in functions.php function send_email(){ $from = "Admin <[email protected]>"; $to = "[email protected]"; $subject = "Lamza Activation"; $activationEmail = ''; $headers = "From:" . $from . PHP_EOL; $headers = array('Content-Type: …
Category: Web

WordPress "phpmailer_init" not working for me

I add the following code to the functions.php file. add_action( 'phpmailer_init', 'my_phpmailer_example' ); function my_phpmailer_example( $phpmailer ) { $phpmailer->isSMTP(); $phpmailer->Host = SMTP_HOST; $phpmailer->SMTPAuth = SMTP_AUTH; $phpmailer->Port = SMTP_PORT; $phpmailer->Username = SMTP_USER; $phpmailer->Password = SMTP_PASS; $phpmailer->SMTPSecure = SMTP_SECURE; $phpmailer->From = SMTP_FROM; $phpmailer->FromName = SMTP_NAME; } and wp-config.php // SMTP email settings define( 'SMTP_USER', '{email}' ); define( 'SMTP_PASS', '{password}' ); define( 'SMTP_HOST', '{server}' ); define( 'SMTP_FROM', '{from}' ); define( 'SMTP_NAME', '{name}' ); define( 'SMTP_PORT', '465' ); define( 'SMTP_SECURE', 'ssl' ); define( 'SMTP_AUTH', …
Category: Web

Page returns 404 with POST variables, but not without

I have a problem with my page. I'm trying to make a "Contact Us" page. It's working perfectly fine design-wise. But when I try to send the form to the same page as origin. It returns 404 error. It only happens when I'm sending the form. I've tried both with GET and POST requests. Nothing seems to work. I've even commented out the PHPMailer part. It's caused entirely by the extra variables. If it helps anything, they're "name", "email" and …
Category: Web

How to properly use AWS SES for a contact form?

Overall Goal: To have my contact form send me the details to my personal email How do I want to achieve it?: Not using any plugins Issue: When I use my custom PHPMailer function located in the functions.php, the console tells me that there is a POST http://websitename.test/wp-admin/admin-ajax.php 500 (Internal Server Error) ...................... jquery.js?ver=1.12.4-wp:formatted:4206 I am using Laragon for my local server. Whenever I comment out my custom function that uses PHPMailer, Laragon "catches" the email. But whenever I add …
Category: Web

Create mail form using PHPmailer

I'm learning about coding plugin. I trying to create a form in plugin page and it can send mail. This is my code, but it doesn't work(I did not receive email and did not show any error). add_action('admin_menu', 'add_contact_us_page'); function add_contact_us_page() { add_menu_page( __( 'Contact Us', 'textdomain' ), __( 'Contact Us','textdomain' ), 'manage_options', 'support_form_page', 'support_form', '' ); } function support_form() { ?> <form action="" method="post" enctype="text/plain"> Name:<br> <input type="text" name="name"><br> E-mail:<br> <input type="text" name="email"><br> Message:<br> <input type="text" name="message" size="50"><br><br> <input …
Category: Web

How to use PHPmailer in a function in WordPress

I have a function in the WordPress functions.php file that searches for a condition in user meta and sends an email to a user based on what it finds. I currently use wp_mail() to send the email, and that works. However, I want to use the included PHPMailer class to do this so that I can send the messages via SMTP. I thought I had a solution here: https://codex.wordpress.org/Plugin_API/Action_Reference/phpmailer_init, however, this seems to only apply to system generated messages, not …
Category: Web

User invite email not delivered - related to subdomain?

I have a problem where, on a new install of WordPress, I want to add a new user, but the user is not receiving the email with the confirmation link. I've done some research and understand that this can be due to various factors, but before I start hassling my host's technical support, I wanted to know whether there's some obvious reason this would be happening in my situation. Specifically, my WordPress site is installed at subdomain site.example.com, while my …
Category: Web

How to set up gmail SMTP in Wordpress

I'm trying to set up an SMTP gmail server to send emails from my WordPress site. This is what I've got in my wp-config.php: define( 'SMTP_USER', '[email protected]' ); // Username to use for SMTP authentication define( 'SMTP_PASS', 'password' ); // Password to use for SMTP authentication define( 'SMTP_HOST', 'smtp.gmail.com' ); // The hostname of the mail server define( 'SMTP_FROM', '[email protected]' ); // SMTP From email address define( 'SMTP_NAME', 'My Site Name' ); // SMTP From name define( 'SMTP_PORT', '465' ); …
Category: Web

Should I use wp_mail or PHP's mail?

I have an email system that I am making in a WordPress plugin to send the emails with this code: include(PLUGIN_DIR.'config/class_phpmailer.php'); $email = new PHPMailer(); $email->From = get_option('admin_email'); $email->FromName = 'my name'; $email->Subject = $subject; $email->Body = $body; foreach($emails as $mail) { if(is_email($mail)) { $email->addAddress($mail); } } if($name) { $att = PLUGIN_DIR.'uploads/'.date('Ymd').'_'.$name; $email->AddAttachment($att); } // check if email is sent or not if(!$email->Send()) { echo "Message was not sent <br />PHPMailer Error: " . $email->ErrorInfo; } else { echo "Message …
Category: Web

Why wp_mail() function isn't sending any emails and displaying '0' in Chrome 'Network' response

I'm trying to send emails through WordPress using the wp_mail() function and it doesn't seem to work. It's displaying 0 in Chrome 'Network' response with Status Code:200 OK This is my code part: // Contact form Ajax add_action('wp_ajax_nopriv_submit_contact_form', 'submit_contact_form'); function submit_contact_form(){ if(isset($_POST['email'])) { $email = $_POST['email']; $email_to = "[email protected]"; $host = "ssl://smtp.gmail.com:465"; $username = '[email protected]'; $password = 'passpass'; $email_subject = "You have a new email from $email via company.com website"; $message = $_POST['text']; $headers = array ('From' => $email, 'To' …
Category: Web

phpmailer_init ignored on REST calls

For testing purposes I've set up a mailtrap (dummy SMTP server) to catch all mail in and out of my local site. To do so, I hooked its configuration in the theme's functions.php like this: function mailtrap($phpmailer) { $phpmailer->isSMTP(); $phpmailer->Host = 'smtp.mailtrap.io'; $phpmailer->SMTPAuth = true; $phpmailer->Port = 2525; $phpmailer->Username = '**************'; $phpmailer->Password = '**************'; } add_action('phpmailer_init', 'mailtrap'); The hook worked like a charm so far, and still does for all front-facing functionalities. Problem is, I now had to expose some …
Category: Web

Redirect to another page after submission using wp_mail

I'm trying to redirect to user to another page after the form has been submitted using wp_mail. // Hooking up our functions to WordPress filters add_filter( 'wp_mail_from', 'wpb_sender_email' ); add_filter( 'wp_mail_from_name', 'wpb_sender_name' ); // Email Sender add_action('wp_ajax_mySendEmail', 'mySendEmail'); add_action('wp_ajax_nopriv_mySendEmail', 'mySendEmail'); function mySendEmail() { $name = $_POST['name']; $email = $_POST['email']; $contact_no = $_POST['contact_no']; $debts_value = $_POST['debts_value']; $how_much = $_POST['how_much']; $employment_type = $_POST['employment_type']; $page_id = $_POST['page_id']; $keyword = $_POST['keyword']; $to = [ "[email protected]" ]; $subject = ''; $mybody = ''; $mybody .='<table>'; …
Category: Web

Emailing passwords: Setup installed on home server using XAMPP

I've just delved into the WP world and all in all it's going quite well. I have a server at home that I'm using to host the sites. All is working fine except the password emails are not being sent when a user registers. I've hunted quite a lot online but none of the posts that I've found relate specifically to my scenario. Someone hints at 'all I need to do is set the correct ini options' but that's where …
Category: Web

How to setup SMTP for only one specific wp_mail()

I just want to setup SMTP for a specific instance of wp_mail(). I have tested plugins like "Easy WP SMTP" and also checked how to set up SMTP manually but all these apply to the entire site and then every email from the site is sent through the SMTP account. I don't want to send any other emails like newsletters or comment approval emails through the same SMTP account.
Category: Web

How can I use get_bloginfo('admin_email') in a custom PHP file?

How can I use get_bloginfo('admin_email') in a custom PHP file located in the parent theme root directory? I've built a custom form and a PHP mail script separately, but now I'd like to send the form data to the WP Admin email address with Bcc. $headers = "MIME-Version: 1.0" . "\r\n"; $headers .= "Content-type:text/html;charset=UTF-8" . "\r\n"; $headers .= 'From: <[email protected]>' . "\r\n"; $headers .= 'Bcc: <'. get_bloginfo('admin_email');'>'. "\r\n"; mail("[email protected]","Form Application",$admin_email_body,$headers); Do I need to include Wordpress functions in the PHP …
Category: Web

About

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