Blog

Magento – Send Email


Untuk mengirim email di magento kita dapat dengan mudah melakukannya dengan menggunakan Zend_Mail
Berikut contohnya :

/**
 * Send email
 */
public function sendEmail()
{
    $fromEmail = "[email protected]"; // sender email address
    $fromName = "John Doe"; // sender name
 
    $toEmail = "[email protected]"; // recipient email address
    $toName = "Mark Doe"; // recipient name
 
    $body = "This is Test Email!"; // body text
    $subject = "Test Subject"; // subject text
 
    $mail = new Zend_Mail();        
 
    $mail->setBodyText($body);
 
    $mail->setFrom($fromEmail, $fromName);
 
    $mail->addTo($toEmail, $toName);
 
    $mail->setSubject($subject);
 
    try {
        $mail->send();
    }
    catch(Exception $ex) {
        // Saya asumsikan anda mempunyai custom_modul.
        // Jika tidak, anda dapat mengganti 'modulku' dengan default magento 'customer'
        Mage::getSingleton('core/session')
            ->addError(Mage::helper('modulku')
            ->__('Unable to send email.'));
    }
}

Selesai, semoga membantu 😀