【问题标题】:Having troubles to send mails in 1and1 hosting在 1and1 主机中发送邮件时遇到问题
【发布时间】:2013-09-20 20:43:09
【问题描述】:

我有一个 1and1 帐户,我尝试使用 symfony2.3 和 swift_mailer 发送电子邮件,但这是不可能的。

我没有任何错误,我已经检查了 symfony 日志,但什么也没有。

这是我的实现(在一个动作中):

$message = \Swift_Message::newInstance()
    ->setSubject('Hello Email')
    ->setFrom('test@domain.com')
    ->setTo('myuser@mydomain.com')
    ->addCc('other@mydomain.com')
    ->setBody( "test body" )
;
$mailer = $this->get('mailer');
$result = $mailer->send($message, $fails);

//$fails receive a empty array
//$result get value 1

这是配置:

swiftmailer:
    transport: smtp                  #i also try mail and sendmail
    host:      smtp.1and1.mx         #i also try smtp.1and1.es, auth.smtp.1and1.fr
    username:  someone@mydomain.net  #the complete email someone@mydomain.net(this account is active, i'm able to login in webmail...) 
    password:  mypass
    spool:     { type: memory }
    encryption: tls                  # i also try without this setting

没有用,甚至,我尝试使用 gmail 配置:

swiftmailer:
    transport: gmail
    host:      smtp.gmail.com    #with and without this parameter
    username:  %mailer_user%     #the complete email someone@gmail.com and without domain
    password:  %mailer_password% #the gmail password

同样的结果。

我做错了什么? 1and1 支持只需将此链接发送给我:

http://faq.1and1.es/email/email/informacion_email/9.html

更新:

如果我在配置中删除 { type: memory } 我得到了这个错误:

Fatal error: Uncaught exception 'Swift_TransportException' with message 'Connection could not be established with host smtp.1and1.es [Connection refused #111]...

有什么帮助吗?

【问题讨论】:

    标签: php email symfony swiftmailer


    【解决方案1】:

    而不是 mail.php,转到 .env 并设置 MAIL_DRIVER 属性。这项工作在 1 和 1 上进行。

    MAIL_DRIVER=mail
    MAIL_HOST=smtp.1and1.es
    MAIL_PORT=25
    MAIL_USERNAME=<xxxxxx@xxxx>
    MAIL_PASSWORD=<xxxxxx>
    MAIL_ENCRYPTION=tls
    

    【讨论】:

      【解决方案2】:

      我们遇到了 Swiftmailer 在使用内存假脱机时不发送电子邮件的问题。我们最终更改为文件假脱机,然后设置一个 cron 作业来执行 swiftmailer 命令将其发送出去 (app/console swiftmailer:spool:send -e=prod)

      【讨论】:

        【解决方案3】:

        转到 config/mail.php

        改变这一行

        'driver' => 'env('MAIL_DRIVER', 'smtp')',
        

        为此

        'driver' => 'mail',
        

        如果您的代码在 localhost 中运行,则通过此更改它也将在 1and1 中运行

        【讨论】:

        • 这个答案: - 关注 Laravel 5 特定配置而不是 Symfony2/3 配置, - 使用 PHP dotenv 库,但 Symfony 没有, - 是 PHP dotenv 库的错误用法,你应该不要更改配置文件的默认值,而是在项目根目录编辑 .env 文件, - 强制通过 PHP mail() 方法发送邮件,这对于大量邮件来说是一种不好的做法(每个套接字一个套接字) mail) - 假设 PHP 函数可以在具有任何配置的任何系统上运行,这可能是错误的
        • 你是对的。我将把这个答案留在这里,让人们知道这个错误。
        猜你喜欢
        • 1970-01-01
        • 2022-08-18
        • 2018-08-06
        • 1970-01-01
        • 2018-05-16
        • 1970-01-01
        • 1970-01-01
        • 2012-04-06
        • 2016-02-04
        相关资源
        最近更新 更多