magento 发送邮件,通过magento的机制发送邮件 - magento send custom email


1

system-->email template ,新建一个邮件模板,得到ID

2

设置template_id为这个id

$template_id = Mage::getStoreConfig("wailian/product/send1")+0;	 //后台配置
$mailSubject = Mage::getModel('core/email_template')->load($template_id)->getTemplateSubject();
$sender //发送人
$name //接收人的名字
$email //接收人的邮箱地址
//发送人的邮箱地址,是magento里面的,这里就不需要设置了



2

$storeId = Mage::app()->getStore()->getId();
				$translate  = Mage::getSingleton('core/translate');
				$sendemailmodel = Mage::getModel('core/email_template')
							->setTemplateSubject($mailSubject)
							->sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);
				$result_email = $sendemailmodel->getSentSuccess();
				
				if($result_email){
					$datetime = date("Y-m-d H:i:s");
					$sc->setStatus(1)->setSendTime($datetime)->save();
				}else{
					
				}

$result_email //代表发送邮件是否成功的状态。

参考文献:

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

More or less a few arrays to setup, I would suggest tacking onto an observer event (or a core rewrite, in which case you'll find the send function for customer registrations in the mage core customer folder!) to send your custom script out (there's a list of the observers available if you google!):

Declare the sender as an array:

$sender = Array('name'  => 'You',
        'email' => 'you@domain.com');

The recipient address, just literally needs to be a string, similarly to the mail subject.

$email = 'customer@customer.com';

Set your template id:

$templateId = 40;

And finally declare your custom variables to be sent along to the template:

$vars = Array('nameOfCustomer' => $customerName,
              'shippingDetails' => $shipping,
              'storeName' => $store_name,
              'storeURL' => $store_url,
              'orderId' => $orderId);

Followed up with the send function, i tend to just leave the $name as a null var:

$storeId = Mage::app()->getStore()->getId();
$translate  = Mage::getSingleton('core/translate');
Mage::getModel('core/email_template')
->setTemplateSubject($mailSubject)
->sendTransactional($templateId, $sender, $email, $name, $vars, $storeId);

Then in your template call the var as literal for example:

{{var storeName}}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~······







  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值