Swiftmail不发送附件$ _FILES tmp [英] Swiftmail not sending attachment $_FILES tmp

查看:138
本文介绍了Swiftmail不发送附件$ _FILES tmp的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我真的坚持使用这种swiftmail方式发送电子邮件附件。我的电子邮件似乎没有交付。我发送电子邮件,它只是ruturns没有任何错误,但当我检查我的邮件没有交付。请帮忙!我解决了所有事情,除了attach()函数之外,一切都起作用。我不知道有什么问题谢谢我的代码。

Im really stuck with this swiftmail method of sending email with attachment. My emails never seem to be delivered. I send the email and it just ruturns without any errors but when I check my mail nothing is delivered. Please help! I troubleshooted everything and everything works except for the attach() function. I dont know whats wrong. Heres my code.

<?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);

?>


推荐答案

糟糕!没有关系,我解决了myslef。

Oops! Never mind, I solved it myslef.

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

I assigned $_FILES['attachment']['tmp_name'] to a temporary variable and it worked!

不知道为什么,但是解决了这个问题。

Dont know why but that solved it for me.

这是我的代码;

// 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']);

这篇关于Swiftmail不发送附件$ _FILES tmp的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆