Fast email delivery

I downloaded Swift Mailer from my website and try to send a simple email with the following code

<?php require_once 'lib/swift_required.php'; $transport = Swift_SmtpTransport::newInstance('smtp.example.org', 25) ->setUsername('your username') ->setPassword('your password') ; $mailer = Swift_Mailer::newInstance($transport); //Create a message $message = Swift_Message::newInstance('Wonderful Subject') ->setFrom(array(' john@doe.com ' => 'John Doe')) ->setTo(array(' receiver@domain.org ', ' other@domain.org ' => 'A name')) ->setBody('Here is the message itself') ; //Send the message $result = $mailer->send($message); 

? >

as soon as I run the page on which it throws an error

  Warning: fsockopen() [function.fsockopen]: php_network_getaddresses: getaddrinfo failed: No such host is known. in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php on line 233 Warning: fsockopen() [function.fsockopen]: unable to connect to smtp.anyhost.com:25 (php_network_getaddresses: getaddrinfo failed: No such host is known. ) in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php on line 233 Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.domain.com [php_network_getaddresses: getaddrinfo failed: No such host is known. #0]' in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php:235 Stack trace: #0 E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php(70): Swift_Transport_StreamBuffer->_establishSocketConnection() #1 E:\web_sites\swift_mail\lib\classes\Swift\Transport\AbstractSmtpTransport.php(101): Swift_Transport_StreamBuffer->initialize(Array) #2 E:\web_sites\swift_mail\lib\classes\Swift\Mailer.php(74): Swift_Transport_AbstractSmtpTransport->start() #3 E:\web_sites\swift_mail\test.php(33): Swift_Mailer->send(Object(Swift_Message)) #4 {main} thrown in E:\web_sites\swift_mail\lib\classes\Swift\Transport\StreamBuffer.php on line 235 

if i delete the line

  $result = $mailer->send($message); 

then execute the page and not display an error message, as soon as I add the above line to send email, I got an error.

my source server, port and user id and passwords are correct in my file.

thanks

+4
source share
3 answers

It is looking for smtp.domain.org server, but cannot solve it.

If you look at the line that the last step in the stack trade is called on, you can see how it throws an exception:

 if (!$this->_stream = fsockopen($host, $this->_params['port'], $errno, $errstr, $timeout)) { throw new Swift_TransportException( 'Connection could not be established with host ' . $this->_params['host'] . ' [' . $errstr . ' #' . $errno . ']' ); } 

Therefore, you need to either enter a valid smtp server, or wrap the send () line in try / catch to catch the exception and either register it somewhere or ignore it

+4
source

Errors tell you everything you need to know:

 getaddrinfo failed: No such host is known. 

The specified SMTP server (smtp.domain.org) does not exist, so the script mailer cannot connect to it to send e-mail. At least the domain.org domain exists, so maybe they have an SMTP server named something else:

 marc@panic :~$ host -t soa domain.org domain.org has SOA record ns.domain.org. sales.domain.org. 1267596439 10800 3600 604800 3600 marc@panic :~$ host -t mx domain.org domain.org mail is handled by 10 mail.domain.org. marc@panic :~$ host domain.org domain.org has address 208.109.97.130 domain.org mail is handled by 10 mail.domain.org. 

Specify another SMTP host that exists and try again.

+3
source

Please control if the port you are using is really the port used by your mail server. I ran into a similar problem and finally saw that I am using port 25 with yahoo instead of 465.

0
source

Source: https://habr.com/ru/post/1304801/


All Articles