【问题标题】:Swiftmail not sending attachment $_FILES tmpSwiftmail 不发送附件 $_FILES tmp
【发布时间】:2014-07-13 14:29:04
【问题描述】:

我真的坚持使用这种带有附件发送电子邮件的 swiftmail 方法。我的电子邮件似乎从未送达。我发送了电子邮件,它只是 ruturns 没有任何错误,但是当我检查我的邮件时,什么都没有送达。请帮忙!我排除了所有问题,除了 attach() 函数外,一切正常。我不知道怎么了。这是我的代码。

<?php

//I didnt add my validations and variables above.....

require_once('./swiftmailer/lib/swift_required.php');

$transport = Swift_SmtpTransport::newInstance('smtp.host.com', 25)
->setUsername('user')
->setPassword('pass');

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

$message = Swift_Message::newInstance()
->setSubject('Online Form')

->setFrom(array($from_email => $full_name))

->setTo(array('email@mail.com' => 'Jack'))

->setBody(''.$message_temp.'')

->attach(Swift_Attachment::fromPath($_FILES['attachment']['tmp_name'])

->setFilename($_FILES['attachment']['name']));

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

?>

【问题讨论】:

    标签: php forms email attachment swiftmailer


    【解决方案1】:

    哎呀!没关系,我自己解决了。

    我将 $_FILES['attachment']['tmp_name'] 分配给了一个临时变量,它起作用了!

    不知道为什么,但这为我解决了。

    这是我的代码;

    // Swiftmail commands ====================================
    require_once('./swiftmailer/lib/swift_required.php');
    
    $transport = Swift_SmtpTransport::newInstance('smtp.host.com', 587)
    ->setUsername('email@host.com')
    ->setPassword('pass');
    
    $mailer = Swift_Mailer::newInstance($transport);
    
    $message = Swift_Message::newInstance()
    ->setSubject($subject_temp)
    
    ->setFrom(array($from_email => $full_name))
    
    ->setTo(array('email@host.com' => 'Jack'))
    
    ->setBody($message_temp)
    
    ->attach(Swift_Attachment::fromPath($file_temp_name)
    
    ->setFilename($name_of_file));
    
    $result = $mailer->send($message);
    
    // Swiftmail commands ====================================
    

    其中 $file_temp_name = $_FILES['attachment']['tmp_name'];$name_of_file = basename($_FILES['attachment']['name']);

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-11-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-05-22
      • 1970-01-01
      • 1970-01-01
      • 2013-09-04
      相关资源
      最近更新 更多