wp_mail is not working in loop

0 Votes
    1015 Views

I am using wp_mail function, but it is not working in loop. Below is my code that i used

$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.0rn";
$headers .= "Content-type: text/html; charset=utf-8rn";

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

`

This is my code that I used in for loop. I have different email id and each mail id have different message,but in loop mail can’t be work.


Please signup or login to answer this question.