SendAsDenied error when sends an email using Office365
Home » BLOG » Web development » SendAsDenied error when sending an email using Office365

SendAsDenied error when sending an email using Office365

category:  Web development, WordPress

Recently I work with one of my client WordPress websites that uses the Microsoft Office365 as mail sending. I already configured the mail sending in WordPress. Everything seems correct. However, I check the PHP error log and I found the error message says:



The Microsoft Office365 SMTP server is rejecting the set “From” address.


The email account that you set in the mail configuration, must present in “From” field of the outgoing emails.

For example, you use your Office365 email account as “” in the mail configuration. It means you website will send an email out using Office365 with “” email account. To get rid of the SendAsDenied error, in all “From” field for the email settings in your website, the email must be “” ONLY.

Fixing in WordPress

In WordPress, you can add the snippet code below in your functions.php file at the active theme.

add_filter('wp_mail_from', 'change_contact_from_address', 999);
function change_contact_from_address() {
     return '';

With wp_mail_form filter, we will make sure the “Form” field in the email settings in your WordPress website, will use “” ONLY. We pass 999 which is the highest priority to make sure that nothing will override our setting.

Additional fixing in Woocommerce in WordPress

If your site uses the Woocommerce plugin, you must set the “From” field at the