我还尝试使用PHPMailer发送图像。但这也行不通。现在我该怎么办?这是代码。
<?php
require("PHPMailer.php");
$mail =new PHPMailer();
$mail->IsSMTP();
$mail->Host = "smtp.gmail.com";
$mail->SMTPAuth = true;
$mail->Username = 'sender@gmail.com';
$mail->Password = 'password';
$mail->From="sender@gmail.com";
$mail->FromName="My site's mailer";
$mail->Sender="sender@gmail.com";
$mail->AddReplyTo("recipient@gmail.com", "Replies for my site");
$mail->Subject = "Your invoice";
$mail->IsHTML(false);
$mail->AddAttachment('k.jpeg', 'koala.jpeg');
// attach files/invoice-user-1234.pdf, and rename it to invoice.pdf
$mail->Body = "Please find your invoice attached.";
if(!$mail->Send())
{
echo "Error sending: " . $mail->ErrorInfo;
}
else
{
echo "Letter is sent";
}
?>
答案 0 :(得分:0)
请将图像更改为base64。试试这个。
if (isset($_FILES['uploaded_file']) &&
$_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK) {
$mail->AddAttachment($_FILES['uploaded_file']['tmp_name'],
$_FILES['uploaded_file']['name']);
}
和函数AddAttachment
public function AddAttachment($path,
$name = '',
$encoding = 'base64',
$type = 'application/octet-stream')
答案 1 :(得分:0)
或者您也可以尝试
<form id="form1" name="form1" method="post" action="form_phpm_mailer.php" enctype="multipart/form-data">
可能是您没有使用
enctype="multipart/form-data"
答案 2 :(得分:0)
邮件服务器的主机名可能有问题
$mail->Host = gethostbyname('smtp.gmail.com'); // if your network does not support SMTP over IPv6