PHP、Swift 邮件程序问题
当我单击联系页面上的“提交”按钮,尝试提交使用 swift-mailer 的表单时,我得到以下信息:
警告:fopen(上传/) [function.fopen]:打开失败 流:没有这样的文件或目录 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php 第131行
Fatal error: Uncaught exception 'Swift_IoException' with message 'Unable to open file for reading [uploads/]' in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php:133
Stack trace:
#0 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php(77): Swift_ByteStream_FileByteStream->_getReadHandle()
#1 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(660): Swift_ByteStream_FileByteStream->read(8192)
#2 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(337): Swift_Mime_SimpleMimeEntity->_readStream(Object(Swift_ByteStream_FileByteStream))
#3 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(448): Swift_Mime_SimpleMimeEntity->getBody()
#4 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(463): Swift_Mime_SimpleMimeEntity->toString()
#5 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 133
尽管错误消息显示“没有这样的文件或目录”,但服务器上存在完整路径。 可能是什么问题? 提前谢谢大家! 圣诞快乐!
When I click submit button on my contact page, trying to submit a form that uses swift-mailer, I get this:
Warning: fopen(uploads/)
[function.fopen]: failed to open
stream: No such file or directory in
/home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php
on line 131
Fatal error: Uncaught exception 'Swift_IoException' with message 'Unable to open file for reading [uploads/]' in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php:133
Stack trace:
#0 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php(77): Swift_ByteStream_FileByteStream->_getReadHandle()
#1 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(660): Swift_ByteStream_FileByteStream->read(8192)
#2 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(337): Swift_Mime_SimpleMimeEntity->_readStream(Object(Swift_ByteStream_FileByteStream))
#3 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(448): Swift_Mime_SimpleMimeEntity->getBody()
#4 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/Mime/SimpleMimeEntity.php(463): Swift_Mime_SimpleMimeEntity->toString()
#5 /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ in /home/polycys2/public_html/html/swift-mailer/lib/classes/Swift/ByteStream/FileByteStream.php on line 133
The full path exists on the server, although the error message says 'no such file or directory.
What could be the problem?
Thank you all in advance!
And merry Christmas!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
您需要提供上传的完整路径,而不是实际路径,因为这将被解释为相对于尝试打开附件的类文件。
在将路径传递给 Swift 之前尝试使用
realpath
。You need to supply the full path to
uploads
not a realtive path because that is going to be interpreted as relative to class file that tries to open your attachment.Try using
realpath
before passing the path to Swift.谢谢大家的帮助!
问题是我的心不在焉 - 我忘记在那里创建“上传”目录。
现在效果很好。
谢谢你!
Thank you all for your help!
The problem was my absentmindedness - I forgot to create 'upload' directory there.
Now it works fine.
Thank you!
这对我有用:
Controller.php
和 embed-mail.php
我希望这对你有用
This works for me:
Controller.php
And embed-mail.php
I hope this works for you
从错误消息来看,似乎您正在指定需要文件路径的目录。可能是因为缺少应该包含文件名的变量。
From the error messages, it seems as if you were specifying a directory where a file path is needed. Maybe because of a missing variable that is supposed to contain the file name.