CMS, 原创, 服务器

wordpress发送邮件mail()函数修改为smtp

当然对于不了解代码的网站主使用插件是最简单有效的方法,这里就不介绍了,网上的资料太多了。 因为个人没有使用这种方式,这里介绍另外的一种方式,直接修改源代码。 修改源代码涉及到2个文件 wp-includes 下面的 pluggable.php 和 class-phpmailer.php pluggable.php 文件中搜到

$phpmailer->IsMail();

修改为

//$phpmailer->IsMail();
$phpmailer->IsSMTP();

在修改class-phpmailer.php

 /**
     * The From email address for the message.
     * @type string
     */
    public $From = 'xxxxxxx@xxx.com'; //这里改为你希望使用发送邮件的邮箱地址

    /**
     * The From name of the message.
     * @type string
     */
    public $FromName = '风火家人网'; //这里是希望显示的名字

找到Mailer修改为smtp 这里默认的时mail

/**
     * Which method to use to send mail.
     * Options: "mail", "sendmail", or "smtp".
     * @type string
     */
    public $Mailer = 'smtp';

找到并修改发送邮件的信息配置

/**
     * SMTP hosts.
     * Either a single hostname or multiple semicolon-delimited hostnames.
     * You can also specify a different port
     * for each host by using this format: [hostname:port]
     * (e.g. "smtp1.example.com:25;smtp2.example.com").
     * Hosts will be tried in order.
     * @type string
     */
    public $Host = 'smtp.163.com'; //这里使用的时163邮箱

    /**
     * The default SMTP server port.
     * @type int
     * @Todo Why is this needed when the SMTP class takes care of it?
     */
    public $Port = 25; //如果你下面的SMTPSecure使用的ssl 这里需要使用993或465

    /**
     * The SMTP HELO of the message.
     * Default is $Hostname.
     * @type string
     * @see PHPMailer::$Hostname
     */
    public $Helo = '';

    /**
     * The secure connection prefix.
     * Options: "", "ssl" or "tls"
     * @type string
     */
    public $SMTPSecure = ''; //默认留空Port将使用25

    /**
     * Whether to use SMTP authentication.
     * Uses the Username and Password properties.
     * @type bool
     * @see PHPMailer::$Username
     * @see PHPMailer::$Password
     */
    public $SMTPAuth = true; //这里永远都要写true

    /**
     * SMTP username.
     * @type string
     */
    public $Username = 'xxxxxx@xx.com'; //你需要使用发送邮件的邮箱

    /**
     * SMTP password.
     * @type string
     */
    public $Password = 'xxxxxx'; //邮箱密码

通过上面这些信息你就可以正常发送邮件了, 如果你也在使用多站点的时候不能够正常发送邮件,比如注册接收不到邮件,重置密码能够接收到邮件,请看这篇 WordPress多站点注册用户收不到邮件,其他时候邮件正常接收

(2321)

Related Post