magento的邮件非常的领过,但是使用起来有点复杂,下面是实用的zend机制发送邮件的简单方法,如下:
public
function
sendEmail()
{
$fromName
=
"John Doe"
;
// sender name
$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
) {
// I assume you have your custom module.
// If not, you may keep 'customer' instead of 'yourmodule'.
Mage::getSingleton(
'core/session'
)
->addError(Mage::helper(
'yourmodule'
)
->__(
'Unable to send email.'
));
}
}
如果想发送html代码
则实用方法:
$mail = new Zend_Mail("UTF-8");
$mail
->setBodyHtml(
$body
);
如果想用magento的邮件机制,可以参看如下链接:http://magentocookbook.wordpress.com/2009/06/26/magento-email/