<?php
require_once '../plugin/swift/lib/swift_required.php';
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('pod51003.outlook.com',587,'tls')
->setUsername('user#connect.polyu.hk')
->setPassword('pw')
;
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
// Create a message
$message = Swift_Message::newInstance('Wonderful Subject')
->setFrom(array('john#doe.com' => 'John Doe'))
->setTo(array('foodil#hotmail.com', 'foodil#yahoo.com.hk' => 'A name'))
->setBody('Here is the message itself')
;
// Send the message
$result = $mailer->send($message);
printf("Sent %d messages\n", $result);
?>
It turned out:
Fatal error: Uncaught exception 'Swift_TransportException'
with message 'Expected response code 250 but got code "501", with message "501 5.5.4 Invalid domain name "'
in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php:422
Stack trace:
#0 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(306): Swift_Transport_AbstractSmtpTransport->_assertResponseCode('501 5.5.4 Inval...', Array)
#1 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php(224): Swift_Transport_AbstractSmtpTransport->executeCommand('HELO [::1]??', Array, Array)
#2 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(323): Swift_Transport_EsmtpTransport->executeCommand('HELO [::1]??', Array)
#3 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php(272): Swift_Transport_AbstractSmtpTransport->_doHeloCommand()
#4 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(124) in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php on line 422
Actually I follow the tutorial straightly, so is that any thing I omitted in my code? The SMTP server information is valid.
External SMTP setting:
Server name: pod51003.outlook.com - you can also see the note below on how to determine the server name
Port: 587
Encryption method: TLS
after adding the line: there is another error:
Warning: stream_socket_enable_crypto() [streams.crypto]: this stream does not support SSL/crypto in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\StreamBuffer.php on line 102
Fatal error: Uncaught exception 'Swift_TransportException'
with message 'Unable to connect with TLS encryption'
in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php:283
Stack trace:
#0 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\AbstractSmtpTransport.php(124): Swift_Transport_EsmtpTransport->_doHeloCommand()
#1 C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Mailer.php(79): Swift_Transport_AbstractSmtpTransport->start()
#2 C:\xampp\htdocs\fyp\mail\send.php(26): Swift_Mailer->send(Object(Swift_Message))
#3 {main} thrown in C:\xampp\htdocs\fyp\plugin\swift\lib\classes\Swift\Transport\EsmtpTransport.php on line 283
Try adding this line here as shown:
// Create the Transport
$transport = Swift_SmtpTransport::newInstance('pod51003.outlook.com',587,'tls')
->setUsername('user#connect.polyu.hk')
->setPassword('pw')
;
// ADD THIS LINE
$transport->setLocalDomain('[127.0.0.1]');
// Create the Mailer using your created Transport
$mailer = Swift_Mailer::newInstance($transport);
I'm guessing your SMTP server doesn't like/understand IPv6, based on the response you are getting to the HELO command.
Related
I am developing a Laravel-5.4 application that connect to some outlook/Hotmail mailbox using imap. From time to time (about 30%) i get this error when i try to connect using:
try {
$imap_open = imap_open($this->imapPath . $this->folder, $this->username, $this->password, OP_READONLY) or die('Cannot connect to : ' . $this->imapPath . ' ' . imap_last_error());
} catch (\Exception $e) {
$output = new ConsoleOutput();
$output->writeln('Imap Connect Exception : ' . $e->getMessage());
}
Note: imapPath and username and password are hard coded so they remain the same in every request.
The error is not catchable by try_catch, so it block my entire request.
The error i get is:
[Thu Apr 27 12:39:08 2017] PHP Fatal error: Uncaught exception 'ErrorException'
with message 'Unknown: [CLOSED] IMAP connection broken (server response) (errfl
g=2)' in Unknown:0
Stack trace:
#0 [internal function]: Illuminate\Foundation\Bootstrap\HandleExceptions->handle
Error(8, 'Unknown: [CLOSE...', 'Unknown', 0, Array)
#1 {main}
thrown in Unknown on line 0
what i want is to catch this Exception or Error if that is possible so i can re-connect again to the mailbox when the connection is broken.
When a query is made, it retuns 404, invalid json error.
I use 8083 as port. Is there any another port for api.
Below is the code I use. Any help is welcome.
<?php
require '/vendor/autoload.php';
$client = new InfluxDB\Client('153.148.25.44', '8083');
$database = $client->selectDB('Meters');
$result = $database->getQueryBuilder()
->select('*')
->from('GDATA')
->limit(2)
->getResultSet()
->getPoints();
//$result = $database->query('select * from GDATAlimit LIMIT 5;');
//$points = $result->getPoints();
//$lastQuery = $client->getLastQuery();
echo '<pre>';
var_dump($result);
?>
Tested database connection, it is working.
Version is 0.13
Fatal error:
Uncaught exception 'InvalidArgumentException' with message 'Invalid JSON' in C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\ResultSet.php:30
Stack trace: #0 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Driver\Guzzle.php(100): InfluxDB\ResultSet->__construct('404 page not fo...')
#1 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Client.php(198): InfluxDB\Driver\Guzzle->query()
#2 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Database.php(78): InfluxDB\Client->query('Meters', 'SELECT * FROM "...', Array)
#3 C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\Query\Builder.php(261): InfluxDB\Database->query('SELECT * FROM "...')
#4 C:\xampp\htdocs\projectone\home.php(10): InfluxDB\Query\Builder->getResultSet()
#5 {main} thrown in C:\xampp\htdocs\projectone\vendor\influxdb\influxdb-php\src\InfluxDB\ResultSet.php on line 30
API port for InfuxDB v0.13 is 8086. I was using 8083, which is used for web.
I write the following code in test.php
<?php
require_once 'Zend/Mail.php';
require_once 'Zend/Mail/Transport/Smtp.php';
$subject="send my email from qq to 163";
$mailbody='stay hungry stay foolish';
$envelope='2546606474#qq.com';
$config = array('auth' => 'login',
'username' => '2546606474',
'password' => 'XXXXXXXXXXX');
$transport = new Zend_Mail_Transport_Smtp('smtp.qq.com',$config);
$mail = new Zend_Mail('GBK');
$mail->setBodyHtml($mailbody);
$mail->setFrom($envelope, '2546606474');
$mail->addTo('kanonwind#163.com','kanonwind');
$mail->setSubject('we create future with our hands');
$mail->send($transport);
?>
I test in localhost and I successfully get an email from 2546606474#qq.com
then I upload the files to my to my web to test,mistakes occur:
Fatal error: Uncaught exception 'Zend_Mail_Protocol_Exception' with message 'Connection timed
out' in /home/u629656826/public_html/mr2/Zend/Mail/Protocol/Abstract.php:277
Stack trace:
#0 /home/u629656826/public_html/mr2/Zend/Mail/Protocol/Smtp.php(167):
Zend_Mail_Protocol_Abstract->_connect('tcp://smtp.qq.c...')
#1 /home/u629656826/public_html/mr2/Zend/Mail/Transport/Smtp.php(199): Zend_Mail_Protocol_Smtp- >connect()
#2 /home/u629656826/public_html/mr2/Zend/Mail/Transport/Abstract.php(348):
Zend_Mail_Transport_Smtp->_sendMail()
#3 /home/u629656826/public_html/mr2/Zend/Mail.php(1194): Zend_Mail_Transport_Abstract->sen
(Object(Zend_Mail))
#4 /home/u629656826/public_html/mr2/test.php(21): Zend_Mail->send(Object
(Zend_Mail_Transport_Smtp))
#5 {main} thrown in /home/u629656826/public_html/mr2/Zend/Mail/Protocol/Abstract.php on line 277
I do not know how to solve the problems.
Although there are many same questions, none of the solutions worked for me. Mail gets sent only if there is only one recipient otherwise generates error below. Also I'm only sending internal emails, no external.
Any idea?
CODE:
$to = 'one#example.com, two#example.com, three#example.com';
$transport = Swift_SmtpTransport::newInstance('192.168.whatever', 25);
$mailer = Swift_Mailer::newInstance($transport);
$message = Swift_Message::newInstance('Test')
->setFrom(array('myself#example.com'))
->setTo(array($to))
->setBody('html content goes here', 'text/html');
$result = $mailer->send($message);
echo $result;
ERROR:
Fatal error: Uncaught exception 'Swift_RfcComplianceException' with message 'Address in mailbox given [one#example.com, two#example.com, three#example.com] does not comply with RFC 2822, 3.6.2.' in C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php:308 Stack trace: #0 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(238): Swift_Mime_Headers_MailboxHeader->_assertValidAddress('lukas.borecki#l...') #1 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(96): Swift_Mime_Headers_MailboxHeader->normalizeMailboxes(Array) #2 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php(60): Swift_Mime_Headers_MailboxHeader->setNameAddresses(Array) #3 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\SimpleHeaderFactory.php(60): Swift_Mime_Headers_MailboxHeader->setFieldBodyModel(Array) #4 C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\SimpleHeaderSet.php(75): Swift_Mime_SimpleHead in C:\wamp\www\ssl\swift_emailer\lib\classes\Swift\Mime\Headers\MailboxHeader.php on line 308
LOOKED AT:
Swift website
swift mailer error 'Swift_RfcComplianceException'....
Google forum
And many more.
Try
$to = array('one#example.com', 'two#example.com', 'three#example.com');
....
->setTo($to)
TRy this example with swiftmailer:
parameters.yml
destinatarios: [email1, email2, email3]
services:
your service name:
class: your namespace
arguments: ["%destinatarios%"]
the class of the service:
protected $destinatarios;
public function __construct($destinatarios)
{
$this->destinatarios = $destinatarios;
}
->setCc($this->destinatarios)
Fatal error: Uncaught exception 'Zend_Controller_Dispatcher_Exception'
with message 'Invalid controller specified (error)'
in C:\xampp\htdocs\zend\library\Zend\Controller\Dispatcher\Standard.php:248 Stack trace:
#0 C:\xampp\htdocs\zend\library\Zend\Controller\Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend\library\Zend\Application\Bootstrap\Bootstrap.php(97):
Zend_Controller_Front->dispatch()
#2 C:\xampp\htdocs\zend\library\Zend\Application.php(366):
Zend_Application_Bootstrap_Bootstrap->run()
#3 C:\xampp\htdocs\intern\lc.intern\public\index.php(26):
Zend_Application->run()
#4 {main} Next exception 'Zend_Controller_Exception'
with message 'Invalid controller specified (error)'
#0 C:\xampp\htdocs\zend\library\Zend\Controller\Front.php(954):
Zend_Controller_Dispatcher_Standard->dispatch(Object(Zend_Controller_Request_Http), Object(Zend_Controller_Response_Http))
#1 C:\xampp\htdocs\zend\library\Zend\Application\B
in C:\xampp\htdocs\zend\library\Zend\Controller\Plugin\Broker.php on line 336
my code for sending mail is as follows:
$mail = new Zend_Mail();
$mail->addTo('myemail#gmail.com', 'my name')
->setFrom('myemanil#gmail.com', 'my name')
->setSubject('My Subject')
->setBodyText('Email Body')
->send();
when I remove the last line i.e., send() then it works fine , but to send a mail we require send() :-P
I'm stuck here ...
please help me ...
thanks in advance
It looks to me like two things happening here:
The send() method is throwing an exception. Since you are not specifying a $transport object, it is attempting to use standard sendmail as a default. It looks like you are using Windows. Do you have sendmail installed? I, too, get exceptions when sending on my local Windows dev environment. Maybe test with an smtp-based transport?
The thrown exception is triggering the error handler, so it is looking for the ErrorController::errorAction(). The message you see is the result of a missing or incorrectly placed ErrorController.
Just thinking out loud.
First of all, please update to the latest ZF stable branch.
As a quickfix, you should try to replace your code with this :
$mail = new Zend_Mail();
$mail->addTo('myemail#gmail.com', 'my name')
->setFrom('myemanil#gmail.com', 'my name')
->setSubject('My Subject')
->setBodyText('Email Body');
$mail->send();
Depending on the ZF version you are using, method chaining could be the problem here.
try like this
example from my project
$options = array(
'auth' => 'login',
'username' => 'username#gmail.com',
'password' => 'password',
'ssl' => 'tls',
'port' => 587
);
$mailTransport = new Zend_Mail_Transport_Smtp('smtp.gmail.com', $options);
Zend_Mail::setDefaultTransport($mailTransport);
$m = new Zend_Mail('UTF-8');
$m->setHeaderEncoding(Zend_Mime::ENCODING_BASE64);
$m->addTo("username#gmail.com");
$m->setFrom('username2b#gmail.com', 'username');
$m->setSubject('usertext');
$errortext = "report";
$m->setBodyHtml($errortext, 'UTF-8', Zend_Mime::ENCODING_BASE64);
$m->send();
you have to set the default transport for your application. Where you are writing the code, in the constructor of the class, you have to use this.
function __construct() {
$tr = new Zend_Mail_Transport_Smtp(<your smtp IP address>);
Zend_Mail::setDefaultTransport($tr);
}
Note: Along with the above code, please check in your php.ini file of your apache server for the following setting. The below option should be uncommented.
extension=php_openssl.dll