I'm trying to get Magento to send transactional emails via our external mail server. I've tried using the SMTP Pro extention, but that didn't work.
I've changed the getMail function in /app/code/core/Mage/Core/Model/Email/Template.php to:
public function getMail()
{
if (is_null($this->_mail)) {
$my_smtp_host = 'xxx';
$my_smtp_port = '587';
$config = array(
'port' => $my_smtp_port, 'auth' => 'login',
'username' => 'xxx',
'password' => 'xxx' );
$transport = new Zend_Mail_Transport_Smtp($my_smtp_host, $config);
Zend_Mail::setDefaultTransport($transport);
$this->_mail = new Zend_Mail('utf-8');
}
return $this->_mail;
}
but the emails are still sending from the local server.
(I know editing core files is bad, this is solely for testing purposes.)
Any ideas on where I'm going wrong?
you may achieve that by setting up a relay between magento server and external mail server. no code changes are necessary if it is an option.
Related
I am developing a website with new version 3.0 of CakePHP Framework. I am working on localhost and would like to send an email after a user has filled a form. Below is the code in my controller to send the email.
public function index(){
if ($this->request->is('post'){
$email = new Email();
$email->from([$this->request->data["sender"] => "Sender"]
->to("myEmail#hotmail.com")
->subject($this->request->data["Subject"])
->send($this->request->data["message"]);
}
}
When this code is executed nothing happen, no error, no message in my mailbox. I have seen that it exist in cakephp3.0 a class called DebugTransport but I don't know how to use it in order to debug my code. Someone has already use it ?
Hi thanks everyone for your answer.
By using mailjet.com I was able to send e-mails in localhost. Below the different steps:
Step 1
Create an account on mailjet website
Step 2
In app.php add a new entry in the table EmailTransport. The different parameter host, port, username and password can be found on mailjet website.
'EmailTransport' => [
'default' => [
'className' => 'Mail',
// The following keys are used in SMTP transports
'host' => 'localhost',
'port' => 25,
'timeout' => 30,
'username' => 'user',
'password' => 'secret',
'client' => null,
'tls' => null,
],
'mailjet' => [
'host' => 'in-v3.mailjet.com',
'port' => 587,
'timeout' => 60,
'username' => 'xxxxx',
'password' => 'xxxxx',
'className' => 'Smtp'
]
],
Step 3
In your controller
<?php
namespace App\Controller;
use App\Controller\AppController;
use Cake\Network\Email\Email;
class ContactController extends AppController {
var $helpers = array('Html');
public function index(){
if($this->request->is('post')){
$userName = $this->request->data['firstname'] . " " . $this->request->data['lastname'];
$email = new Email();
$email->transport('mailjet');
try {
$res = $email->from([$this->request->data['email'] => $userName])
->to(['myEmail#hotmail.com' => 'My Website'])
->subject('Contact')
->send($this->request->data['message']);
} catch (Exception $e) {
echo 'Exception : ', $e->getMessage(), "\n";
}
}
}
You had to use a SMTP server for delivery your email from your localhost in your config email.
There are 2 ways to achieve this:
Use it from a real server with a mail configuration
Use SMTP server for your test on your localhost. there are a lot of SMTP server with let you use it.
see mailjet.com
Here's my controller action.
public function actionContact()
{
$model=new ContactForm;
if(isset($_POST['ContactForm']))
{
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
$headers="From: {$model->email}\r\nReply-To: {$model->email}";
mail(Yii::app()->params['adminEmail'],$model->subject,$model->body,$headers)`enter code here`;
Yii::app()->user->setFlash('contact','Thank you for contacting us. We will respond to you as soon as possible.');
$this->refresh();
}
}
$this->render('contact',array('model'=>$model));
}
It validates the data and shows up the success message. but email isn;t sent to the adminEmail address which is mine.
Thanks.
If it is validating and showing flash messages, then it has to do with mail server, nothing to do with yii. I advise you look into mail server and see if it is running properly.
if you are doing in a localhost you must configure your mail server.you can use smtp for sending mails from localhost.If it is in mail server no need to configure.In yout config/main.php you can do like this for localhost
'mail' => array(
'class' => 'application.extensions.yii-mail.YiiMail',
'transportType' => 'php',
'transportOptions'=>array(
'host'=>'yourhostname',
'port'=>'your port no'
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
Note: i am using YiiMail Extension
I'm trying to create a form that sends an email using SMTP authentication, but I keep receiving an error. I've read a bunch of posts online and this is the code I've come up with so far. Does anyone see anything wrong with the code below? Any help would be greatly appreciated.
Thanks
Bob
$configSMTP = array(
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
$transport = new Zend_Mail_Transport_Smtp('mail.server.com', $configSMTP);
$mail = new Zend_Mail();
$mail->setReplyTo($config['replyto']);
$mail->setBodyText($message);
$mail->setFrom($params[$config['emailID']], $params[$config['nameID']]);
$mail->addTo($config['sendto']);
$mail->setSubject($config['subject']);
try {
$mail->send($transport);
} catch(Exception $ex) {
Mage::getSingleton('core/session')->addError('There was an error submitting your request.');
}
Mandril's SMTP uses TLS.
http://help.mandrill.com/entries/21738477-What-SMTP-ports-can-I-use-
Enable it in your config array.
$configSMTP = array(
'ssl' => 'tls',
'port' => 587,
'auth' => 'login',
'username' => '***',
'password' => '***'
);
Would direct you maybe to section on resource plugins form Zend Mail. Give a better list of the options and shows how to assign them through your app.ini file.
That said, assuming your arguments are valid that looks fine.
What exception are you catching? You must be getting an error message. Can you telnet from this machine to your mail server? Want to eliminate network/auth issues.
It's hard to say without knowing what exception you're getting.
There might be several reasons, can you connect to the SMTP-server.. Is the port 587 really open? Do you have a firewall, and if so, might it be blocking the connection to that port? Are you really sure those credentials are valid? Have you tried manually connecting to the SMTP-server?
If not, see how you can do it with Telnet: How to test an SMTP server using Telnet
You could also try using a transactional email service. That way you wouldn't need to manage an SMTP-server or even think about deliverability, etc. You would just outsource it to someone else.
There are various providers, some of them are:
AlphaMail
Mandrill
PostageApp
If you're using AlphaMail, you could just use the AlphaMail PHP-client and send your emails like the example below:
include_once("comfirm.alphamail.client/emailservice.class.php");
$email_service = AlphaMailEmailService::create()
->setServiceUrl("http://api.amail.io/v1")
->setApiToken("YOUR-ACCOUNT-API-TOKEN-HERE");
$person = new stdClass();
$person->userId = "1234";
$person->firstName = "John";
$person->lastName = "Doe";
$person->dateOfBirth = 1975;
$response = $email_service->queue(EmailMessagePayload::create()
->setProjectId(12345) // You AlphaMail project (determines template, options, etc)
->setSender(new EmailContact("Sender Company Name", "from#example.com"))
->setReceiver(new EmailContact("Joe Doe", "to#example.org"))
->setBodyObject($person) // Any serializable object
);
The templates are constructed in the AlphaMail Dashboard using the Comlang templating language. This means that you can easily edit your emails at any time, without having to dig through code. Templates in Comlang look something like:
<html>
<body>
<b>Name:</b> <# payload.firstName " " payload.lastName #><br>
<b>Date of Birth:</b> <# payload.dateOfBirth #><br>
<# if (payload.userId != null) { #>
Sign Up Free!
<# } else { #>
Sign In
<# } #>
</body>
</html>
I want to send a local e-mail through exchange server
but zend give me this Message
"A connection attempt failed because the connected party did not properly respond after a period of time, or established connection
failed because connected host has failed to respond."
this is my code
$mailTransport =
new Zend_Mail_Transport_Smtp('smtpserver.edu.com', array(
'auth' => 'login',
'username' => 'dummy.edu.com',
'password' => '123456',
'port' => '25',
));
Zend_Mail::setDefaultTransport($mailTransport);
$mail = new Zend_Mail();
$mail->setFrom('dummy.edu.com');//anas.azmeh#ucti.edu.my');
$mail->setBodyHtml('some message - it may be html formatted text');
$mail->addTo('dummy.edu.com', 'recipient');
$mail->setSubject('subject');
$mail->send();
I tried the same code in gmail configuration and it works perfectly
please help me as fast as possible
$mail = new Mail\Message();
$mail->setBody("Send Mail");
$mail->setFrom('test#gmail.com', 'Test Site');
$mail->addTo($email_id, 'Test Site');
$mail->setSubject('Your connection is not stablish');
$transport = new Mail\Transport\Sendmail();
$transport->send($mail);
I think that port 25, 23 and 587 are blocked
because I tried to telnet them but it give me fail, so the problem may come from these blocking
I am able to send SMTP Emails from my local server machine in CakePHP while I am not able to do the same on my GoDaddy live server, in CakePHP.
Any ideas for the same?
Thanks
Answer is below as per my experience with GoDaddy:
Below code is working for me over GoDaddy server using CakePHP SMTP Email:
Email.php file inside config folder - CakePHP 2.4 MVC version:
// for Live Server GoDaddy.com domain
public $smtp = array(
'transport' => 'Smtp',
'host' => 'ssl://smtpout.asia.secureserver.net', // important
'port' => 465, // important
#'timeout' => 30,
'username' => 'no-reply#godaddy-domain.com',
'password' => 'password',
#'tls' => false,
#'log' => false,
'charset' => 'utf-8',
'headerCharset' => 'utf-8',
);
And here is the controller file code below:
// Controller Code to Send Actual Email
// email configuration
$Email = new CakeEmail('smtp');
$Email->from(array('no-reply#godaddy-domain.com' => 'App Name'))
->sender('no-reply#godaddy-domain.com', 'App Name')
->to(array($email))
->bcc(array('xyz#xyz.com'))
->subject('Test Email from GoDaddy')
->emailFormat('both')
->send($hash.'<br><strong>My</strong> message 45 قبل الميلاد، مما يجعله أكثر من');
Hope it helps !
Thanks
Update your code to check for an error message:
if(!$this->Email->send()) {
CakeLog::write('debug', $this->Email->smtpError);
}
Then check the /app/tmp/logs/debug file on the server.