我準備爲網站創建一個表單頁面,用戶需要填寫很多字段並將其發送到指定的電子郵件。我能夠成功發送電子郵件,但在郵件中找不到附件。使用PHPMailer在郵件中添加附件失敗
$model->attributes=$_POST['ContactForm'];
if($model->validate())
{
require("class.phpmailer.php");
$mail = new PhpMailer;
$mail->IsSMTP();
$mail->SMTPSecure = "ssl";
$mail->Host = 'smtp.gmail.com';
$mail->SMTPAuth = true;
$mail->SMTPSecure = true;
$mail->Username = '[email protected]';
$mail->Port = '465';
$mail->Password = '*****';
$mail->SMTPKeepAlive = true;
$mail->Mailer = "smtp";
$mail->IsSMTP(); // telling the class to use SMTP
$mail->SMTPAuth = true;
$mail->CharSet = 'utf-8';
$mail->SMTPDebug = 0;
$mail->SetFrom('[email protected]', 'name');
$mail->Subject = $_POST['ContactForm']['subject'];
$mail->AltBody = 'To view the message, please use an HTML compatible';
$mail->MsgHTML($_POST['ContactForm']['body']);
$mail->AddAttachment($_POST['ContactForm']['filename']); /**Problem is here */
}
我試着改變$ _POST爲$ _FILES太添加附件。
我的觀點:
<?php $form=$this->beginWidget('CActiveForm', array(
'htmlOptions' => array('enctype' => 'multipart/form-data') ,
)); ?>
<?php echo $form->fileField($model, 'filename');?>
<?php echo $form->error($model, 'filename');?>
嘗試'的var_dump()''$ _FILES'和'$ _POST' – Dinistro
如果我傾倒$ _FILES,它給未定義指數誤差「文件名」。但是,我已經在我的模型中定義了它們 – user3496974
但數據在$ _FILES中? – Dinistro