I would like a php script that when specific products, which I define, have a qty of higher than 0. I automatically receive an e-mail from this.

Anyone have an idea how I can easily make a script out of this? My current script looks like this, but this will always sent a email.

I would only like to sent a email when the foreach got products.


ini_set('display_errors', 'On');
ini_set('memory_limit', '4G');


$productIds = array(500004,540603,529536,513045);

$products = Mage::getModel('catalog/product')->getCollection()->addAttributeToFilter('entity_id', array('in' => $productIds))->joinField('qty','cataloginventory/stock_item','qty','product_id=entity_id','{{table}}.stock_id=1','left');

$message =
            <table name='contact_seller' style='border-collapse:separate';> 
                    foreach($products as $product){
                    if ($product->getQty() > 0){
                        $message .="<tr>
                            <td>" .$product->getSku()."</td>
                $message .= "</tbody>

$to      = 'test@test.com';
$subject = 'Subject';

$headers = 'From: test@test.com' . "\r\n" .
    'MIME-Version: 1.0' . "\r\n".
    'Content-type:text/html; charset=iso-8859-1' . "\r\n".
    'Reply-To: test@test.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();

mail($to, $subject, $message, $headers);

1 Answer 1


Is it sth different from standard Product Alert in magento?

System -> Configuration -> Catalog -> Catalog -> Product Alerts -> Allow Alert When Product Comes Back in Stock?

  • No that's not working well, I need a custom script. See my edit and current code.
    – JGeer
    Nov 28, 2019 at 15:33

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.