我使用phpmailer作为联系表单。我用联系表格为上传文件/图像添加了附件字段。但我无法集成php函数用于文件附件。我在php中很弱,但这对我来说非常重要,我可以在我的联系表单中添加它。
请有人帮助我。我的表单代码和php代码如下。提前谢谢。
// **这是html标记
<form action="mobileapp.php" method="post" enctype="multipart/form-data">
<h2>Your Contact Info</h2>
<p>Your First Name* <br />
<input type="text" name="firstName" id="firstName" required />
</p>
<p>Your Last Name* <br />
<input type="text" name="lastName" id="lastName" required />
</p>
<p>Your Email* <br />
<input type="email" name="email" id="email" required />
</p>
<p>Upload Your logo<br />
<input type="file" name="uploaded_file" id="uploaded_file">
</p>
</form>
// * 这是phpmailer代码
<?php
/* config start */
$emailAddress = 'test@yourmail.com';
/* config end */
require "class.phpmailer.php";
$msg=
'First Name:'.$_POST['firstName'].'<br />
Last name:'.$_POST['lastName'].'<br />
Email:'.$_POST['email'].'<br />
';
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "Subject";
$mail->MsgHTML($msg);
$mail->Send();
echo'<script> window.location="../index.html"; </script> ';
?>
答案 0 :(得分:1)
试
<form action="" method="post" enctype="multipart/form-data">
<h2>Your Contact Info</h2>
<p>Your First Name* <br />
<input type="text" name="firstName" id="firstName" required />
</p>
<p>Your Last Name* <br />
<input type="text" name="lastName" id="lastName" required />
</p>
<p>Your Email* <br />
<input type="email" name="email" id="email" required />
</p>
<p>Upload Your logo<br />
<input type="file" name="uploaded_file" id="uploaded_file">
</p>
<input type="submit" name="submit" />
</form>
<?php
if(isset($_POST['submit'])) {
$emailAddress = 'ex@ex.com';
require "class.phpmailer.php";
$msg = 'First Name:'.$_POST['firstName'].'<br /> Last name:'.$_POST['lastName'].'<br /> Email:'.$_POST['email'].'<br />';
move_uploaded_file($_FILES["uploaded_file"]["tmp_name"], $_FILES["uploaded_file"]["name"]);
$mail = new PHPMailer();
$mail->IsMail();
$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "Subject";
$mail->MsgHTML($msg);
$mail->AddAttachment( $_FILES["uploaded_file"]["name"]);
$mail->Send();
echo'<script> window.location="../index.html"; </script> ';
}
?>