0

我正在使用 PHP 和 Swiftmailer 开发一个邮件系统:看看我的脚本:

// HTML 表单

<form method="POST" action="mailer.php">

<label>Sender's Email:</label>
<input type="text" name="email" tabindex="1" placeholder="Sender's Email" required/>

<label>Subject:</label>
<input type="text" name="subject" tabindex="2" placeholder="Enter Email Subject" required />

<label>Attach File:</label>
<input type="file" name="attach" tabindex="3" value=" " />

<label for="Message">Message:</label><br />
<textarea name="message" tabindex="4" placeholder="Enter Message" rows="20" cols="20"></textarea>

<input type="submit" name="submit" value="Send" class="submit-button" />

</form>

// Mailer.php --> 邮件的消息部分

$message = Swift_Message::newInstance()

->setSubject($_POST['subject'])

->setFrom($_POST['email'])

->setBody('<em>' . $_POST['message'] . '!</em>', 'text/html')

->addPart('Here is the message in plain text!', 'text/plain');

$message->attach(Swift_Attachment::fromPath($_POST['attach']));

$mailer->batchSend($message);`

///////////////////////////////////////// ////////////////////////////////

我的两个问题是:

1.当我从我的根目录以外的不同目录上传文件时,它给了我这个错误:

警告:fopen(.open child's locket.jpg): failed to open stream: No such file or directory in C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php on line 125 致命错误:在 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php:126跟踪:#0 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php(75): Swift_ByteStream_FileByteStream->_getReadHandle() #1 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib \classes\Swift\Mime\ContentEncoder\Base64ContentEncoder.php(34): Swift_ByteStream_FileByteStream->read(8190) #2 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(500): Swift_Mime_ContentEncoder_Base64ContentEncoder->encodeByteStream(Object(Swift_ByteStream_FileByteStream), Object(Swift_Transport_StreamBuffer), 0, 78) #3 C:\xampp\ htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(517): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\ 在 C:\xampp \htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php 在第 126 行\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(517): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\ in C :\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php 在第 126 行\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(517): Swift_Mime_SimpleMimeEntity->toByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\ in C :\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php 在第 126 行

2.当我不附加文件时(我应该允许用户这样做),它给了我这个错误:

警告:fopen():C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php 中的文件名不能为空,第 125 行致命错误:未捕获异常 'Swift_IoException' 并带有消息'无法打开用于在 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\FileByteStream.php:126 中读取 []' 的文件 堆栈跟踪:#0 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes \Swift\ByteStream\FileByteStream.php(75): Swift_ByteStream_FileByteStream->_getReadHandle() #1 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\ContentEncoder\Base64ContentEncoder.php(34): Swift_ByteStream_FileByteStream- >read(8190) #2 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(500):Swift_Mime_ContentEncoder_Base64ContentEncoder->encodeByteStream(Object(Swift_ByteStream_FileByteStream), Object(Swift_Transport_StreamBuffer), 0, 78) #3 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\SimpleMimeEntity.php(517): Swift_Mime_SimpleMimeEntity-> toByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\S 在 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\第 126 行的 FileByteStream.phptoByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\S 在 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\第 126 行的 FileByteStream.phptoByteStream(Object(Swift_Transport_StreamBuffer)) '#4 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\Mime\S 在 C:\xampp\htdocs\MailerProject_Test\SwiftMailer\lib\classes\Swift\ByteStream\第 126 行的 FileByteStream.php

4

0 回答 0