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>
Related
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.
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'm building a CakePHP website that sends an e-mail like this:
$email = new CakeEmail('default');
$email->template('test');
$email->emailFormat('html');
$email->to(array('john_doe#example.com' => 'John Doe'));
$email->subject('Test E-mail');
$email->helpers(array('Html', 'Text'));
$email->viewVars(
array(
...
)
);
if ($email->send()) {
$this->Session->setFlash('The e-mail was sent!', 'default', array('class' => 'alert alert-success'));
}
else {
$this->Session->setFlash('An unexpected error occurred while sending the e-mail.', 'default', array('class' => 'alert alert-error'));
}
I'd like to be able to capture the HTML rendered by the e-mail in a variable in addition to actually sending the e-mail. This way, I can record in the database the exact content of the e-mail's body. Is this doable?
Per line 50 of the MailTransport class, it appears the actual send() function returns the message and the header. So instead of:
if($email->send()) {
Try:
$mySend = $email->send();
if($mySend) {
//...
Then, $mySend should be an array:
array('headers' => $headers, 'message' => $message);
Thats what I do in my EmailLib:
https://github.com/dereuromark/tools/blob/2.0/Lib/EmailLib.php
it logs email attempts and captures the email output into a log file (email_trace.log) in /tmp/logs/ - if you are in debug mode it will only log (no emails sent - this has been proven quite useful for local delopment).
you can write a similar wrapper for your case.
but if you want to write it back into the DB Dave's approach seems to fit better.
im getting this error when sending emails with cake's email component
[smtpError] => 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 r11sm77490vbx.11
any ideas? here's my code...
$this->Email->to = array(' juan <name#gmail.com>');
$this->Email->from = 'name#gmail.com';
$this->Email->subject = 'Welcome to our really cool thing';
$this->Email->template = 'simple_message';
$this->Email->sendAs = 'both';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'name#gmail.com',
'password'=>'********',
);
You have a space there before your name, which could possibly be sending the wrong data. Have you tried the code without that extra space?
Well, the link in the error message to google's support forums say that the username and password combination are incorrect. I'd recommend that you try logging in to that gmail account with the specified password, just to triple check that you're not mistaken. That happens a lot to me, all the time.
Secondly, are you sure you're supposed to put the #gmail.com in for the username? Maybe it should just be 'name' rather than 'name#gmail.com'.
Apart from that stated by #Travis ... i would also suggest that the from should also be constructed in this format "Name " ... otherwise I don't think the email will go through.
First time using the email component... I followed the book instruction and I set this
function sendNewUserMail($id) {
$User = $this->User->read(null,$id);
$this->Email->to = array('MyEmai#gmail.com');
$this->Email->from = 'MyEmai#gmail.com';
$this->Email->subject = 'Welcome to our really cool thing';
$this->Email->template = 'simple_message';
$this->Email->sendAs = 'text';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'MyEmail#gmail.com',
'password'=>'*********'
);
$this->set('User', $User);
$this->Email->delivery = 'smtp';
$this->Email->send();
$this->set('smtp_errors', $this->Email->smtpError);
}
I try to run the method, but nothing happens... I created the layouts, the elements, and put var $component = array('Email');
I'm getting this error
Unable to find the socket transport "ssl" - did you forget to enable
it when you configured PHP?: 16
by the way I at home so no firewalls, no blocking etc
Gmail smtp requires a secure connection and it looks like your PHP configuration doesn't have ssl enabled. Open php.ini and look for a line that looks like
;extension=php_openssl.dll
or
#extension=openssl.so
and uncomment it (remove the ; or the #), then restart PHP.
If you can't find such line there you may need to install OpenSSL first.