文件的最简单方法是什么:<input type="file" name="clanlogo">
并通过电子邮件将其发送到"12345@email.com" 我已经研究了,但发现了超级复杂的代码和东西。我需要它作为附件发送。在 PHP 中。这是我到目前为止的代码:
<?php
## CONFIG ##
# LIST EMAIL ADDRESS
$recipient = "my email Here";
# SUBJECT (Contact Form/Remove)
$subject = "Volunteer Form";
# RESULT PAGE
$location = "thank_you.html";
## FORM VALUES ##
# SENDER
$email = $_REQUEST['email'] ;
# MAIL BODY
$body .= "First Name: ".$_REQUEST['first_name']." n";
$body .= "Last Name: ".$_REQUEST['last_name']." n";
$body .= "Email: ".$_REQUEST['email']." n";
$body .= "Volunteer Choice: ".$_REQUEST['dropdown']." n";
$body .= "Questions: ".$_REQUEST['comments']." n";
# add more fields here if required
## SEND MESSGAE ##
我只需要一些代码来添加到其中,这将允许我上传文件。
使用 html 表单并添加标记<input type="file" name="uploaded">
然后您可以在 PHP 中像这样处理该文件:
<?php
$file = $_FILES['uploaded'];
if (move_uploaded_file($file['tmp_name'], $destination)) {
// do something
}
// do something
?>
我写不出巨大的代码,这应该是你开始的推动力!这是一个快速指南。现在要附加它,您可以将其作为 ajax 请求发送到服务器,存储文件的路径,然后在发送电子邮件时再次从数据库中提取路径。
下载 PHPMailer 类并尝试这个...
<html>
<head>
<title>PHPMailer - Mail() basic test</title>
</head>
<body>
<?php
require_once('class.phpmailer.php');
$mail = new PHPMailer();
$mail->SetFrom('name@yourdomain.com', 'First Last');
$mail->AddReplyTo("name@yourdomain.com","First Last");
$address = "12345@email.com";
$mail->AddAddress($address, "John Doe");
$mail->Subject = "PHPMailer Test Subject via mail()";
$mail->AltBody = "To view the message, please use an HTML compatible email viewer!"; // optional
$mail->MsgHTML($body);
move_uploaded_file($_FILES["file"]["tmp_name"],$destination);
$mail->AddAttachment("$destination"); //Your attachment
//$mail->AddAttachment("images/phpmailer.gif"); // attachment
//$mail->AddAttachment("images/phpmailer_mini.gif"); // attachment
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
- 这是来自 PHPMailer 类的一个例子