wp_mail()或mail()无法使用Wordpress联系表单

时间:2015-08-03 05:04:15

标签: php wordpress email phpmailer

我在这个网站上有一个联系表格http://dil33pm.in/contact/ 发送按钮连接到具有此基本测试代码的文件contact-form.php。

<?php
   $to = "dil33pm@gmail.com";
   // Email subject and body text
   $subject = 'wp_mail function test';
   $message = 'This is a test of the wp_mail function: wp_mail is   working';
   $headers = '';
   // Load WP components, no themes
   define('WP_USE_THEMES', false);
   $parse_uri = explode( 'wp-content', $_SERVER['SCRIPT_FILENAME'] );
   require_once( $parse_uri[0] . 'wp-load.php' );
   // send test message using wp_mail function
   try {
     $sent_message = wp_mail( $to, $subject, $message, $headers );
   }catch (Exception $e) {
     error_log('oops: ' . $e->getMessage());
     echo 'error failed because '.$e->getMessage();
   }
   if($sent_message)
   {
    echo '      <div class="alert alert-confirm">
            <h6>'.__("Your message has been sent. Thank You.", 'sr_xone_theme').'</h6>
        </div>';
   }
   else
   {
   echo '       <div class="alert alert-error">
            <h6>'.__("Your message has not been sent", 'sr_xone_theme').'</h6>
        </div>';
   }
   ?>

但我收到错误 - 您的邮件尚未发送。我试过使用PHP的mail()函数,仍然没有好处。 PHP没有返回任何错误,我打开PHP的调试,看看是否有任何错误。

可能有什么不对?我读到了关于设置SMTP的内容,但我不确定真正的问题是什么。我的网站托管在www.axoservers.com

谢谢!

1 个答案:

答案 0 :(得分:0)

此问题因主机而异。我建议使用此插件:https://wordpress.org/plugins/easy-wp-smtp/