In order to allow magento to use SMTP instead of the usual mail function, you need to take the below steps.
- Login to magento admin and go to. System->Configuration->Advanced->System->Mail Sending Settings
- Now here set the host value to your smtp host name like
mail.domain.com
- And then the default port is 25.
- Now you need to change magento file. Do not edit the core file as you will loose your change in an upgrade.
- So copy this file app/code/core/Mage/core/Model/Email/Template.php in to your local, by creating the same folder structure.
- Enable that module.
- Then in Template.php you will have to change the getMail() function as below.
public function getMail()
{
if (is_null($this->_mail)) {
/* changes begin */
$my_smtp_host = Mage::getStoreConfig('system/smtp/host');
$my_smtp_port = Mage::getStoreConfig('system/smtp/port');
$config = array(
'port' => $my_smtp_port,
'auth' => 'login',
'username' => 'email@domain.com',
'password' => 'yourpassword'
);
$transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
Zend_Mail::setDefaultTransport($transport);
/* Changes End */
$this->_mail = new Zend_Mail('utf-8');
}
return $this->_mail;
}
- After this clear your cache.
- Now magento will be able to send emails for you.
- Login to magento admin and go to. System->Configuration->Advanced->System->Mail Sending Settings
- Now here set the host value to your smtp host name like
mail.domain.com
- And then the default port is 25.
- Now you need to change magento file. Do not edit the core file as you will loose your change in an upgrade.
- So copy this file app/code/core/Mage/core/Model/Email/Template.php in to your local, by creating the same folder structure.
- Enable that module.
- Then in Template.php you will have to change the getMail() function as below.
public function getMail()
{
if (is_null($this->_mail)) {
/* changes begin */
$my_smtp_host = Mage::getStoreConfig('system/smtp/host');
$my_smtp_port = Mage::getStoreConfig('system/smtp/port');
$config = array(
'port' => $my_smtp_port,
'auth' => 'login',
'username' => 'email@domain.com',
'password' => 'yourpassword'
);
$transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
Zend_Mail::setDefaultTransport($transport);
/* Changes End */
$this->_mail = new Zend_Mail('utf-8');
}
return $this->_mail;
}
- After this clear your cache.
- Now magento will be able to send emails for you.
what does "into your local" mean?
ReplyDeleteThat means app/code/core/Mage/local/Model/Email/Template.php
DeleteThis comment has been removed by the author.
ReplyDeleteHi, i created this directory and copied the changed template.php file to it. But it doesn't work. When i changed the core module with your function, it worked great. I did everything like you described now, except i don't know what "Enable that module" means.
ReplyDeleteThanks for reply, maybe some things need to be clarified more in your post
Hello Kiran,
ReplyDeleteThanks the post, i have used the above code to send emails ( i had to change the core template ). Now that the mail functions work fine for new registrations and orders but email a friend doesnt work anymore ..'
Any solutions ?