我正试图通过WordPress使用wp_mail()
功能,但似乎不起作用。
它正在显示0
在Chrome“网络”响应中,使用
Status Code:200 OK
这是我的代码部分: // Contact form Ajax
add_action(\'wp_ajax_nopriv_submit_contact_form\', \'submit_contact_form\');
function submit_contact_form(){
if(isset($_POST[\'email\'])) {
$email = $_POST[\'email\'];
$email_to = "info@company.com";
$host = "ssl://smtp.gmail.com:465";
$username = \'myEmail@company.pro\';
$password = \'passpass\';
$email_subject = "You have a new email from $email via company.com website";
$message = $_POST[\'text\'];
$headers = array (\'From\' => $email, \'To\' => $email_to,\'Subject\' => $email_subject);
/*$smtp = Mail::factory(\'smtp\',
array (\'host\' => $host,
\'auth\' => true,
\'username\' => $username,
\'password\' => $password));*/
//$mail = $smtp->send($email_to, $headers, $message);
wp_mail( $email_to, $email_subject, $message );
/*if (PEAR::isError($mail)) {
echo($mail->getMessage());
} else {
echo("Message successfully sent!\\n");
}*/
}
}
error_reporting(E_ALL);
ini_set("display_errors", 1);
哪一部分可能出错?编辑:
这是ajax部分:
// Send button for the "contact form".
$(\'#sendBtn\').click(function(){
//get info
var fullname = $("#fullname").val();
var email = $("#email").val();
var text = $("#text").val();
//send info to php
$.ajax({
beforeSend: function() {
if ( IsEmail(email) == false) {
$(\'#aboutUnsuccess\').show("slow");
$(\'.form_content\').hide("slow");
}
},
url: document.location.protocol+\'//\'+document.location.host+\'/wp-admin/admin-ajax.php\',
type: "POST",
/*action: \'submit_contact_form\',*/
data: ({ "action": "submit_contact_form", "fullname": fullname, "email": email, "text": text }),
success: function (results){
if ( IsEmail(email) == true) {
//hide table
$(\'.form_content\').hide(\'slow\', function() {
$(\'.form_content\').hide( "slow" );
});
//show textboxes
$(\'#aboutSuccess\').show("slow");
$( "#aboutSuccess" ).append( "<iframe id=\\"pixel-thing\\" src=\\"http://54.xx.xx.xx/wp-content/themes/twentyfifteen-child/thePixel.html\\" width=\\"1\\" height=\\"1\\" border=\\"0\\"></iframe>" );
}
}
});
});