wp_mail不在循环中工作

时间:2017-11-02 04:12:12

标签: php wordpress wordpress-theming custom-wordpress-pages

我正在使用wp_mail函数,但它不能在循环中工作。下面是我使用的代码

$productName = '';
$productName = implode(',',$users_arr[$i]['productName']);
$productId = '';
$productId .= implode(',',$users_arr[$i]['productId']);
require('wp-load.php');
ini_set( 'display_errors', 1 );
error_reporting( E_ALL );
$to = $users_arr[$i]['userEmail'];

$subject = 'You have won the auction!';
$headers  = "MIME-Version: 1.0\r\n";
$headers .= "Content-type: text/html; charset=utf-8\r\n";

$message = "<html xmlns=\"http://www.w3.org/1999/xhtml\" lang=\"en\" xml:lang=\"en\">\r\n
<head>\r\n
<title>Hello Test</title>\r\n
</head>\r\n
<body>\r\n
<p></p>\r\n
<p>Congratulations, You have won the auction for ".$productName." and <a href=".$cart_url."?add-to-cart=".$productId." target='_blank'>Pay now</a></p>\r\n
</body>\r\n
</html>";
echo $to;
$mail = wp_mail($to, $subject, $message, $headers);
// wp_trash_post();
sleep(10);
echo 'done ---->'.$mail;

`

这是我在for循环中使用的代码。我有不同的电子邮件ID,每个邮件ID都有不同的消息,但在循环邮件中无法正常工作。

0 个答案:

没有答案