我正在尝试在使用 php 从 gmail 发送邮件时添加附件。但它显示错误......它说Could not access file: hai.jpg
以下是我使用的代码
gmail.php
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>PHPMailer - GMail SMTP test</title>
</head>
<body>
<?php
access to that
date_default_timezone_set('Etc/UTC');
require '../Mail/class.phpmailer.php';
$mail = new PHPMailer();
$mail->IsSMTP();
$mail->SMTPDebug = 2;
$mail->Debugoutput = 'html';
$mail->Host = 'smtp.gmail.com';
$mail->Port = 587;
$mail->SMTPSecure = 'tls';
$mail->SMTPAuth = true;
$mail->Username = "name@gmail.com";
//Password to use for SMTP authentication
$mail->Password = "passwrd";
$mail->SetFrom($_POST['from'], $_POST['from_name']);
$mail->AddReplyTo($_POST['from'],$_POST['from_name']);
$mail->AddAddress($_POST['to'],$_POST['to_name']);
$mail->Subject = 'PHPMailer GMail SMTP test';
$mail->MsgHTML($_POST['message']);
$mail->AltBody = 'This is a plain-text message body';
$mail->AddAttachment($_POST['attachment'],'application/octet-stream');
if(!$mail->Send()) {
echo "Mailer Error: " . $mail->ErrorInfo;
} else {
echo "Message sent!";
}
?>
</body>
</html>
索引.html
<form action="gmail.php" method="POST">
<div>
From Name:<input type="text" name="from_name" />
From:<input type="text" name="from" />
</div>
<div>
To Name:<input type="text" name="to_name" />
To:<input type="text" name="to" />
</div>
<div>
Message:<textarea name="message"></textarea>
</div>
<div>
Attachment:<input type="file" name="attachment" />
</div>
<input type="submit" value ="Submit"/>
</form>
我不知道如果我在这里做正确的方式会怎样。有人可以指导我吗?