我正在使用以下脚本来允许用户上传图像并将其通过电子邮件发送给我。我确实收到了电子邮件,但附件未包含在电子邮件中。它还将发件人电子邮件显示为 root 用户,而不是用户的电子邮件地址。请帮忙。
<?php
ob_start();
require("class.phpmailer.php");
$salutation = $_POST['salutation'];
$firstname = $_POST['firstname'];
$lastname = $_POST['lastname'];
$email = $_POST['email'];
$photo = $_FILES['photo'];
isset($_POST['submit']);
$active_keys = array();
foreach($_FILES[$photo]['name'] as $key => $filename)
{
if(!empty($filename))
{
$active_keys[] = $key;
} }
foreach($active_keys as $key)
{ switch(exif_imagetype($_FILES[$photo]['tmp_name'][$key])) {
case IMAGETYPE_JPEG:
case IMAGETYPE_PNG:
break;
default:
echo "{";
echo "error: 'This is no photo..'\n";
echo "}";
exit(0);
} }
$message = "Photo submitted by: $salutation $firstname $lastname. <br>Comments: $comments.<br>terms:$terms.";
$mail = new PHPMailer();
$mail->From = ($email);
$mail->AddAddress('info@domain.com');
$mail->Subject = "Submitted Photos";
$mail->Body = $message;
$mail->WordWrap = 50;
foreach($FILES['photo']['tmp_name'] as $photo) {
if(!empty($photo)) {
$mail->AddAttachment($photo);
}}
$mail->Send();
header("Location: thankyou.php");
exit();
?>