SwiftMailer Connection could not be established with host smtp.mailgun.org [closed]

家住魔仙堡 提交于 2019-12-22 12:14:39

问题


If i use

$transport = Swift_SmtpTransport::newInstance('localhost', 25);

then it's working fine
but when i'm using this settings it's not working

$transport = Swift_SmtpTransport::newInstance('smtp.mailgun.org', 465, 'ssl')
  ->setUsername('mailegun username')
  ->setPassword('mailgun password');

This problem is in "godaddy" and "bluehost" account

but in localhost using xampp it's working fine

    <?php
    ini_set('display_errors', 1);
    ini_set('display_startup_errors', 1);
    error_reporting(E_ALL);
    require_once __dir__.'/vendor/swiftmailer/swiftmailer/lib/swift_required.php';
    $userBody="user mail";
    $userSub = "user subject";
    //$transport = Swift_SmtpTransport::newInstance('localhost', 25);
    $transport = Swift_SmtpTransport::newInstance('smtp.mailgun.org', 465, 'ssl')
      ->setUsername('mailegun username')
      ->setPassword('mailgun password'); 
// and also not working for gmail settings
// $transport = Swift_SmtpTransport::newInstance('smtp.gmail.com', 465, 'ssl')
   //   ->setUsername('gmail username')
     // ->setPassword('gmail password');


    $userMailer = Swift_Mailer::newInstance($transport);

    $message = Swift_Message::newInstance('Wonderful Subject')
          ->setFrom(array('ex1@gmail.com' => 'user1'))
          ->setTo(array('ex2@gmail.com'=> 'user2'))
          ->setBody('Test Message Body')
        ;

    $sendUserMail = $userMailer->send($message,$F);
    var_dump($sendUserMail);


    ?>

回答1:


This is a well-known problem: GoDaddy does not allow outbound SMTP; you must relay through thir servers. This is covered in the PHPMailer troubleshooting guide, the principles of which still apply to SwiftMailer.



来源:https://stackoverflow.com/questions/36841051/swiftmailer-connection-could-not-be-established-with-host-smtp-mailgun-org

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!