Some modification and customization tips for emails in WordPress

WBOY
Release: 2016-07-29 09:10:26
Original
969 people have browsed it

Change the email content type to HTML
In WordPress Send emailYou need to use the wp_mail() function, but the default type of email content is "text/plain", which means HTML is not supported.

If you want to add HTML code to the email content, in addition to sending the header information of "Content-Type: text/", you can also use filters to modify it uniformly.

/**
  *WordPress 更改邮件内容类型为 HTML
  *http://www.endskin.com/mail-content-type-html/
*/
function Bing_set_html_content_type_html(){
  return 'text/html';//可以自定义类型
}
add_filter( 'wp_mail_content_type', 'Bing_set_html_content_type_html' );
Copy after login

In this way, the content of the mailbox supports HTML code by default.

Customized emailSend emailand sender
When using the SMTP plug-in, you can customize the sender and email of the email. There is a question here. How to customize the sending of the email without using the SMTP plug-in? What about the person and the sending email address?

By default, the sender is "WordPress < wordpress@example.com >", so users cannot reply directly, and it is easily judged as spam, resulting in users not receiving it.

If you want to modify the sender and sender email, you only need to use a small code and put it in functions.php (learn more):

/**
  *WordPress 自定义邮件<strong>发送邮件</strong>和发件人
  *http://www.endskin.com/change-mail-from-info/
*/
//发件人
function Bing_wp_mail_from_name(){
  return '斌果';//可自行修改
}
add_filter( 'wp_mail_from_name', 'Bing_wp_mail_from_name' );
 
//<strong>发送邮件</strong>
function Bing_wp_mail_from(){
  return 'admin@endskin.com';//可自行修改
}
add_filter( 'wp_mail_from', 'Bing_wp_mail_from' );
Copy after login

The above has introduced some modification and customization techniques for emails in WordPress, including content on sending emails. I hope it will be helpful to friends who are interested in PHP tutorials.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!