duandanxiu6965 2019-02-10 13:06
浏览 788

使用PHP Swiftmailer时,我们如何解决错误554 5.5.1(没有有效的收件人)?

When testing out our mail server we stumbled accross an error that prevents us from sending mails via PHP, though regular sending/receiving per Mail-in-a-box works without any problems. We are running a separate Ubuntu 18.04 server that only has Mail-in-a-box with all its needed components running.

Output in the error.log text file

PHP Fatal error: Uncaught Swift_TransportException: Expected response code 354 but got code "554", with message "554 5.5.1 Error: no valid recipients "

PHP file

$request_email = $_POST['request-email'];
$request_name = $_POST['request-name'];
$request_text = $_POST['request-text'];

$transport = (new Swift_SmtpTransport('data.abc.xy', 587, 'tls'))
    ->setUsername('contact@abc.xy')
    ->setPassword('*******')
    ->setStreamOptions(array('ssl' => array('allow_self_signed' => true, 'verify_peer' => false)));

$mailer = (new Swift_Mailer($transport));

$message = (new Swift_Message('Name: '. $request_name))
    ->setFrom(['' . $request_email => '' . $request_name])
    ->setTo(['contact@abc.xy'])
    ->setBody('E-Mail: ' . $request_email . $request_text)
    ->setContentType("text/html");

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

What we have tried is to reinstall all of Mail-in-a-box and all of the components and checking everything for spelling mistakes. The ricipient does exist on our mail server and can receive and send mails manually via the client.

  • 写回答

2条回答 默认 最新

  • dongsonglian7303 2019-02-10 13:48
    关注

    The 554 5.5.1 error is the SMTP error "no valid recipients". It can occur if you've misspelled the recipient addresses but it can also occur if you are not properly authenticating to the outgoing server.

    So the problem is that abc.xy is not a registered domain so you can't send an email to this address. I think it's not something related to your code.

    You can catch the Swift_TransportException error and handle it in your own codebase like :

    try {
        $result = $mailer->send($message);
    } 
    catch (Swift_TransportException $e) {
        echo $e->getMessage();
    }
    
    评论

报告相同问题?

悬赏问题

  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测