标签: swiftmailer

有没有办法更改 SwiftMailer 中标头的编码?

我用来SwiftMailer发送电子邮件,但我在UTF-8主题方面遇到一些编码问题。Swiftmailer 默认使用QPHeaderEncoder对电子邮件标头进行编码,并且 safeMap 看起来对某些UTF-8法语字符存在一些问题。我使用的一个主题包含单词 trouv\xc3\xa9 (在法语中找到),当该主题到达用户时,它会显示 trouv。

\n\n

我想使用类似于NativeQPContentEncoder可用作内容编码器的东西,但对于标题只有Base64Quoted Printable编码器。

\n\n

有没有办法解决这个问题,也许我做错了什么,所以我将我正在使用的代码粘贴到这里

\n\n
$message = Swift_Message::newInstance()\n\n// set encoding in 8 bit\n->setEncoder(Swift_Encoding::get8BitEncoding())\n\n// Give the message a subject\n->setSubject($subject)\n\n// Set the From address with an associative array\n->setFrom(array($from => $niceFrom))\n\n// Set the To addresses with an associative array\n->setTo(array($to)) ;\n
Run Code Online (Sandbox Code Playgroud)\n

php swiftmailer symfony

5
推荐指数
1
解决办法
4415
查看次数

LogicException:Symfony\Bundle\SwiftmailerBundle\DataCollector\MessageDataCollector 中缺少默认数据

在 Symfony 2.5.5 和 Swiftmailer 5.3.0 中出现此异常。我完全按照食谱的例子。调用时抛出错误MessageDataCollector#getMessages()

// Check that an e-mail was sent
$this->assertEquals(1, $mailCollector->getMessageCount());

$collectedMessages = $mailCollector->getMessages();
$message = $collectedMessages[0]; 
Run Code Online (Sandbox Code Playgroud)

消息计数断言也失败,值为零。

据我所知,收集者没有在行动中进行任何实际的收集。有任何想法吗?

profiler phpunit swiftmailer symfony

5
推荐指数
1
解决办法
778
查看次数

返回在 Yii 2 的基本邮件程序类中邮件发送失败的错误

我正在使用并且正在使用基本邮件程序类Yii 2中的邮件程序,并且在大多数情况下它工作正常,但有时无法发送......所以我的代码如下:

// Let's start composing the message
$mail = Yii::$app->mailer->compose($view_data, $view_params);

//.........

// Send the message
$send = $mail->send();      
Run Code Online (Sandbox Code Playgroud)

有时$send是,false但我不确定你如何找出它为什么是假的?有没有办法得到使它变成假的错误?

php swiftmailer yii2

5
推荐指数
1
解决办法
8067
查看次数

当我尝试使用 PHP + Swiftmailer 发送电子邮件时出现错误:“501 5.5.4 域名无效”

我正在编写一个非常简单的联系表格,允许蓝领工人通过我们的内联网提交安全问题通知。联系表单以 HTML 格式显示,并要求输入姓名、发件人电子邮件以及要发送的消息。它总是发送到我们的安全电子邮件。

服务器和端口正确。它是一个 Exchange 2010 服务器,我们使用 TSL。服务器配置为能够“匿名”接收电子邮件。我可以通过 telnet 命令进行连接,但当我尝试通过评论框发送邮件时,收到“501 5.5.4 域名无效”错误。

define("EMAIL_SUBJECT", "Safety Concerns");     
    define("EMAIL_TO", "email");        

    // SMTP Configuration
    define("SMTP_SERVER", 'server');                
    define("SMTP_PORT", 25);                                

    // define("UPLOAD_DIR", '/var/www/tmp/');           // Default php upload dir

    // main method. It's the first method called
    function main($contactForm) {

        // Checks if something was sent to the contact form, if not, do nothing
        if (!$contactForm->isDataSent()) {
            return;
        }

        // validates the contact form and initialize the errors
        $contactForm->validate();

        $errors = array();

        // If the contact form …
Run Code Online (Sandbox Code Playgroud)

php email swiftmailer

5
推荐指数
1
解决办法
2万
查看次数

Silex + Swift 邮件程序不起作用

我有一个带有 Swift Mailer 的 Silex 应用程序,但似乎没有从$app['swiftmailer.options'].

我在引导文件中注册了该服务

$app->register(new SwiftmailerServiceProvider());
Run Code Online (Sandbox Code Playgroud)

在我的配置文件中

$app['swiftmailer.options'] = array(
    'host' => 'smtp.mandrillapp.com',
    'port' => '587',
    'username' => 'MY_USERNAME',
    'password' => 'MY_PASSWORD',
    'encryption' => null,
    'auth_mode' => null
);
Run Code Online (Sandbox Code Playgroud)

然后我发送我的电子邮件

$message = \Swift_Message::newInstance()
    ->setSubject($this->app['forum_name'] . ' Account Verification')
    ->setFrom(array('no-reply@domain.com'))
    ->setTo(array('recipient@example.com'))
    ->setBody('My email content')
    ->setContentType("text/html");

$this->app['mailer']->send($message);
Run Code Online (Sandbox Code Playgroud)

send 函数返回,1但电子邮件从未发送过。但是,当我尝试手动创建 的实例时Swift_SmtpTransport,电子邮件会发送。

$transport = \Swift_SmtpTransport::newInstance('smtp.mandrillapp.com', 587)
    ->setUsername('MY_USERNAME')
    ->setPassword('MY_PASSWORD');
...
$mailer = \Swift_Mailer::newInstance($transport);
$mailer->send($message);
Run Code Online (Sandbox Code Playgroud)

所以问题是$app['swiftmailer.options']没有读取或加载。我在这里错过了什么吗?

我正在按照此处的说明进行操作。

php swiftmailer silex mandrill

5
推荐指数
1
解决办法
3064
查看次数

Yii2 如何处理 Swift_TransportException 异常?

尝试使用 swiftmailer 发送邮件时,出现以下错误:

Expected response code 250 but got code "550", with message "550 User test@test.com has exceeded its 24-hour sending limit. Messages to 250 recipients out of 250 allowed have been sent. Relay quota will reset in 1.47 hours.
Run Code Online (Sandbox Code Playgroud)

我已将 swiftmailer 放在 try catch 块中,如下所示:

public function sendMail($emailTemplateName, $subject, $body, $fromEmail, $toEmail)
{
        try
        {
            return Yii::$app->mailer->compose(['html' => $emailTemplateName], ['emailBody' => $body])
                ->setFrom([ $fromEmail => Yii::$app->params['siteTitle'] ])
                ->setTo($toEmail)
                ->setSubject($subject)
                ->send();
        }
        catch(Swift_SwiftException $exception)
        {
            return 'Can sent mail due …
Run Code Online (Sandbox Code Playgroud)

exception-handling swiftmailer yii2 yii2-advanced-app

5
推荐指数
1
解决办法
3229
查看次数

Laravel 邮件 Swift_IoException 无法打开文件进行阅读

我尝试在电子邮件中发送附件,但出现以下错误,但是当我检查给定的 url 文件是否存在并下载工作时。

Swift_IoException in FileByteStream.php line 144:
Unable to open file for reading [http://sendemail.domain.com/attachment/warburg_brochure.pdf]
Run Code Online (Sandbox Code Playgroud)

swiftmailer laravel

5
推荐指数
1
解决办法
1万
查看次数

symfony2 项目上的 Swiftmailer 附件错误(无法打开文件进行阅读)

我正在处理一个 symfony 项目,我有一个表格,必须使用 swiftmailer 发送邮件。为了说明 -> 用户可以在表单的可选文件的上传功能中使用附件。(表单保存在bdd like命令中,提交表单后我们有一个回顾,还有3封邮件(我们不使用附件的两封邮件每次都有效,只有带有附件选项的邮件在我们有一个文件要加入,否则如果我们只使用评论(另一个像路径一样工作的字段可选,邮件正在工作)

我希望我的解释清楚易懂,我的英语不完美,功能也不太容易。由于某些信息的机密性,我只在这里写了与邮件有关的代码,但如果我忘记了某些信息,请告诉我并更新帖子。

当我发送没有附件的邮件时,我没有任何问题,它可以正常工作,但是当我尝试加入文件时,symfony 给我这个错误:

无法打开文件进行阅读 [uploads/6M.jpg]

我试图在 StackOverflow 的其他帖子上找到解决方案,但没有人在工作。所以我会让你帮助我,我希望。

命令实体(我只是将有关文件、路径和上传的代码放在附件中(邮件程序的其余部分/和代码工作):

use Doctrine\Common\Collections\ArrayCollection;
use Doctrine\ORM\Mapping as ORM;
use Symfony\Component\Validator\Constraints as Assert;
use Symfony\Component\Form\Extension\HttpFoundation;

/**
* Commandes
*/
class Commandes
{
// CUSTOM CODE

/**
 * @var string
 */
public $file3;

/**
 * @var string
 */
protected $path3;

public function getAbsolutePath1()
{
    return null === $this->path1 ? null : $this->getUploadRootDir().'/'.$this->id.'.'.$this->path1;
}

public function getWebPath1()
{
    return null === $this->path1 ? null : $this->getUploadDir().'/'.$this->path1;
} …
Run Code Online (Sandbox Code Playgroud)

php forms email swiftmailer symfony

5
推荐指数
1
解决办法
4825
查看次数

Yii2:无法与主机 smtp.gmail.com [连接被拒绝 #111] 在 Godaddy 托管中建立连接

我正在尝试在 Yii2 中使用 Swift Mailer。

我的主持人是 Godaddy,我正在尝试使用 gmail 帐户发送电子邮件。

该代码似乎工作正常,但是当我尝试使用它时,我收到错误消息:无法与主机 smtp.gmail.com 建立连接 [连接被拒绝 #111]

我仔细检查了我使用的 gmail 凭据是否正确。这可能是我的主机的问题,如果是,有办法解决吗?这是代码

'mailer' => [
            'class' => 'yii\swiftmailer\Mailer',
            'transport' => [
                    'class' => 'Swift_SmtpTransport',
                    'host'=>'smtp.gmail.com',
                    'username'=>'myUserName@gmail.com',
                    'password'=>'******',
                    'port'=>'587',
                    'encryption'=>'tls',
                ],
            'useFileTransport' => false, //for the testing purpose, you need to enable this


        ],
I also tried with **`'class' => 'Swift_MailTransport',`**
but the error was not resolved.

The error is 
Run Code Online (Sandbox Code Playgroud)

无法与主机 smtp.gmail.com 建立连接 [连接被拒绝 #111]

请在这方面帮助我。谢谢,

php email smtp swiftmailer yii2

5
推荐指数
1
解决办法
4419
查看次数

Symfony 4.1:如何在 UnitTest 中使用依赖注入 (Swift_Mailer)

在我的 Symfony4.1-项目中,我试图测试一种方法,该方法应该通过单元测试使用 SwiftMailer 发送邮件。

我的测试课看起来像这样

namespace App\Tests;

use App\Controller\UserImageValidationController;
use Symfony\Bundle\FrameworkBundle\Tests\TestCase;

class UserImageValidationControllerTest extends TestCase
{

    private $mailer = null;
    public function __construct(\Swift_Mailer $testmySwiftMailer)
    {
        $this->mailer = $testmySwiftMailer;
    }

    public function testMail()
    {
        $controller = new UserImageValidationController();

        $controller->notifyOfMissingImage(
            'a',
            'b',
            'c',
            'd',
            $this->mailer
        );
    }
}
Run Code Online (Sandbox Code Playgroud)

问题是,当我运行时./bin/phpunit出现异常

未捕获的 ArgumentCountError:函数 App\Tests\UserImageValidationControllerTest::__construct() 的参数太少,0 [...] 且恰好 1 个预期 [...]

看起来在测试环境中 DI 不起作用。

所以我添加了

bind:
    $testmySwiftMailer: '@swiftmailer.mailer.default'
Run Code Online (Sandbox Code Playgroud)

对于我的config/services_test.yaml但我仍然遇到相同的错误。我还添加autowiring: true到该文件(只是为了尝试),但它也不起作用。另外,我尝试使用服务别名,就像文件注释中所述:仍然没有成功。

如何将 swiftmailer 注入到我的测试用例构造函数中?

phpunit unit-testing swiftmailer symfony symfony4

5
推荐指数
1
解决办法
7134
查看次数