Swiftmail not sending attachment $_FILES tmp

送分小仙女□ 提交于 2020-01-03 04:15:08

问题


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

?>

回答1:


Oops! Never mind, I solved it myslef.

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

Dont know why but that solved it for me.

Here's my code;

// 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 ====================================

Where $file_temp_name = $_FILES['attachment']['tmp_name']; and $name_of_file = basename($_FILES['attachment']['name']);



来源:https://stackoverflow.com/questions/23842615/swiftmail-not-sending-attachment-files-tmp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!