简体   繁体   中英

Swiftmailer error 220

The ff code works perfectly when run locally, the problem is when uploaded to our domain host, it throws this error

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Expected response code 250 but got code "", with message ""'

My theory is that the php version on the host is not updated.

Any ideas what is the real cause of this problem? Here is my code. I'm using swiftmailer 5.1.0 and the php version of my local machine is php 5.6.12

$smtp_host_ip = gethostbyname('our_domain_host.ph');
#set the transport
$emailuser1 = $_SESSION['email'];
 $transport = Swift_SmtpTransport::newInstance($smtp_host_ip,587,'tls')->setUsername('username.ph')->setPassword('password');

// Mailer
$mailer = Swift_Mailer::newInstance($transport);

// Create a message
$message = Swift_Message::newInstance('Thank you for answering the survey')
    ->setFrom(array('username.ph' => 'Test')) 
    ->setTo(array($_SESSION['receive_email'] => 'Receiver Name'))
    ->setBody($_SESSION['reply_guest']);

// Send the message
if ($mailer->send($message)) {
    echo 'Mail sent successfully.';
} else {
    echo 'I am sure, your configuration are not correct. :(';
}

I had solved my problem by using swift mailer's logger plugin.

Swift mailer Logger plugin

You could see what the error is by using the logger.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM