Zend_Mail fail to send email, output message : Connection timeout - zend-framework

I try to write codes about sending email using Zend Framework. Here is the code,
$mail = new Zend_Mail('utf-8');
$mailConfig = array(
'auth'=> 'login',
'username' => 'sample#gmail.com',
'password' => 'samplepassword',
'ssl' => 'tls',
'port' => '587';
$tr = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $mailConfig);
Zend_Mail::setDefaultTransport($tr);
$mail->setSubject('test email');
$mail->setBodyText('body');
$mail->setFrom('sample#gmail.com', 'Just a sample');
$mail->addTo('anothersample#gmail.com', 'Another sample');
$mail->send();
These codes work perfectly at my local computer, but failed to send email at the server side with return message "Connection time out". I guess there might be some configuration problem on the server side, but I don't know what it is. Anyone with idea what is going wrong?

Try 'ssl'='ssl' and port 995.

Contact the admin of the server and ask if they allow outgoing communication on port 587.
It seems like they are blocking certain traffic.

Related

passing data to mailgun webhooks in laravel

Im using laravel and configured mailgun to send mails
I want to use webhooks to track them.
so I need to send data with the message so I can track it using the web hook
for example attach a message id to each mail I send
tried to follow the mailgun documnation but no luck
this is my code for sending the mail
$data = array('course_name' => $course_name,'grade' => $grade,'email' => $stud->email,
"v:messageId" => "123");
Mail::send('emails.stud_feedback',$data, function ($message) {
$message->to($this->email)->subject( $this->course);
$message->attach($this->file, ['as' => 'feedback']);
});
according to the documnation the web hook should post me the message id,
but Im not getting it.
what am I doing wrong?
solved by setting headers to the mail:
$message->getHeaders()->addTextHeader('X-Mailgun-Variables', "{'messageid:123}'}");
Use This :
Mail::send('emails.test',[]), function ($message) use ($subject, $from, $emails) {
dd($message->getSwiftMessage()->getId());
});

Laravel 4.1, call error message for specific validation point of one input / possible?

I have a question concerning the Laravel 4.1 validators.
$validator = Validator::make(
array('name' => 'Dayle'),
array('email' => 'required|min:5|unique:users')
);
Is it possible to call a specific validation error for the case when the entered email is not unique? Reading the docs I only saw that one is able to define the error message if the validation for 'email' fails. However, if someone enters an email address but this one is already in the database it would be awesome to show the user exactly that he passed "required" but did not pass "unique".
The third parameter of Validator::make() lets you pass in an array of messages. More on this here: http://laravel.com/docs/validation#custom-error-messages
As it says in the above link, you can specify field-and-rule-specific messages by using the dot syntax email.unique. In your case this would be:
$validator = Validator::make(
array('name' => 'Dayle'),
array('email' => 'required|min:5|unique:users'),
array('email.unique' => 'This email is already being used by another user.'),
);

cakeemail and gmail smtp how to change the FROM field?

I am using cakephp 2.2
THis is my smtp setup in Config/email.php
public $gmail = array(
'host' => 'ssl://smtp.gmail.com',
'port' => 465,
'username' => 'appmailer#someapp.com',
'password' => 'somepassword',
'transport' => 'Smtp'
);
This is my email settings.
App::uses('CakeEmail', 'Network/Email');
$email = new CakeEmail('gmail');
$email->from(array('bigshot#company.com' => 'On Behalf of Big Shot'));
$email->to('client#bigshotclient.com');
$email->subject('[Test -- please ignore] one last test. Remember to hit REPLY to this email');
$email->sender('appmailer#someapp.com');
$email->replyTo('bigshot#company.com', 'Big Shot');
$email->send('Remember to hit REPLY to this email');
WHen the email is sent, the FROM address repeatedly shows
On Behalf of Big Shot<appmailer#someapp.com>
how can i make it such that the FROM appears as the original email address of bigshot#company.com?
By the way, the replyTo works very well.
I am attempting to perfect the mail delivery that is all.
Apparently, Gmail SMTP will always overwrite the FROM field to prevent spamming.
See https://stackoverflow.com/a/3872880/80353
If anyone can help to attach the actual GMail documentation stating this point, that would be great.

Sending email from Magento to fails

I am trying to send an email from a custom module in magento, however it fails to send it.
do i need to include anything or should i make some configuration with my hosting?
Here you can see my code:
$mail = new Zend_Mail();
$mail->setBodyText($mailbody);
$mail->setFrom('admin#gmail.com', 'admin');
$mail->addTo('email#gmail.com', 'client');
$mail->setSubject('Error report');
try {
$mail->send();
Mage::getSingleton('core/session')->addSuccess('Your request has been sent');
}
catch (Exception $e) {
Mage::getSingleton('core/session')->addError('Unable to send.');
}
It's better to use Magento's models for sending email. This way you know it's being send correctly, and get userful errors when it fails
The most simply way:
$email = Mage::getModel('core/email_template');
$email->setSenderEmail('sender#email.com');
$email->setSenderName('name');
$email->setTemplateSubject('Subject');
$email->setTemplateText('emailbody');
$email->send('receiver#mail.com', 'receiver name');
Remember that you host my not support sending mail, or that your provider is blocking port 25. This will result in a message in your exception.log
If you want to see how the final email looks, print $email->getProcessedTemplate() onto your screen
You have to configure your smtp in php.ini
What is your provider ? It's possible to find the smtp server's url, and put it in your php.ini file.

How to find bugs that cause unclean seed of headers

I don't know if I missed something while developing my application using Zend_Framwork, but here's my problem, I can't see any cookies, when I run my application on host server, but on my WAMP server everything worked well ..
I stock on sessions, user information to use it later, so on host server I can't login..
I use Zend_Auth and Zend_Acl, here's my bootstrap
$modelLoader = new Zend_Application_Module_Autoloader ( array ('basePath' => APPLICATION_PATH, 'namespace' => '', 'resourceTypes' => array ('form' => array ('path' => 'forms/', 'namespace' => 'Form_' ) ) ) );
$this->_acl = new Application_Plugin_Acl ();
$this->_auth = Zend_Auth::getInstance ();
I also use Zend_Auth getStorage()->write('...') to write infos in sessions.
And I have nothing related to sessions on my application.ini
So, it is WORKING on WAMP but, not on host servers. I presume you mean to say your VPS or dedicated server or say any cloud.
Zend_Auth uses $_SESSION and it has many functions operating on it. For instance, $_SESSION['Zend_Auth']['storage'] will give you information about what is in your hasIdentity() checking stuff.
So, what you should do is, get this pasted somewhere near the code and run it, just for your reference
echo '<pre>';
print_r($_SESSION);
Also, you can't see Cookies because they are session cookies which has 1 reference on client machine and rest all are on file system (if not configured) of the server.
Hope that helps.
Questions?