我正在尝试设置一个SMTP gmail服务器,以便从我的WordPress站点发送电子邮件。这就是我的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\' ); // SMTP port number - likely to be 25, 465 or 587
define( \'SMTP_SECURE\', \'tls\' ); // Encryption system to use - ssl or tls
define( \'SMTP_AUTH\', true ); // Use SMTP authentication (true|false)
define( \'SMTP_DEBUG\', 1 ); // for debugging purposes only set to 1 or 2
我把这个放在我的主题里
functions.php
文件:
add_action( \'phpmailer_init\', \'send_smtp_email\' );
function send_smtp_email( $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;
}
我在打电话
wp_mail()
在这样的函数中:
function invite_others() {
$team_name = $_GET[\'team_name\'];
$user_id = get_current_user_id();
$user = get_userdata($user_id);
$site = get_site_url();
$message = "blah blah blah";
$subject = "blah";
$admin_email = get_option(\'admin_email\');
foreach($_POST as $name => $email) {
if($email != $_POST[\'invite_others\']){
$headers = "From: ". $admin_email . "\\r\\n" .
"Reply-To: " . $email . "\\r\\n";
$sent = wp_mail($email, $subject, strip_tags($message), $headers);
}
}
}
我从中得到以下错误
wp_mail()
:
SMTP错误:无法连接到SMTP主机
任何帮助都将不胜感激!谢谢