1
ファイルを送信したいときにphpmailer関数でアップロードファイル関数を追加しました。ファイルの名前を表示するだけで、実際のファイルは添付ファイルにありません。PHPMailer attachemnt not working
この問題を解決する方法はありますか。どんな助けもありがとう。あなたが任意のディレクトリにアップロードする必要があり、ここでファイルのアップロード機能を使用していけないする必要が助け
<?php
if(isset($_POST['submit']))
{
$message=
'Full Name: \t '.$_POST['fullname'].'<br />
Subject: \t '.$_POST['subject'].'<br />
Phone: \t '.$_POST['phone'].'<br />
Email: \t '.$_POST['emailid'].'<br />
Attachment: \t '.$_POST['attachment'].'<br />
Comments: \t '.$_POST['comments'].'
';
require 'PHPMailer/PHPMailerAutoload.php';
$mail = new PHPMailer;
//$mail->SMTPDebug = 3; // Enable verbose debug output
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup SMTP servers
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = '[email protected]'; // SMTP username
$mail->Password = '******'; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable TLS encryption, `ssl` also accepted
$mail->Port = 465; // TCP port to connect to
$mail->SetFrom($_POST['emailid'], $_POST['fullname']);
$mail->AddReplyTo($_POST['emailid'], $_POST['fullname']);
$mail->Subject = "New Contact Form Enquiry"; // Subject (which isn't required)
$mail->MsgHTML($message);
$mail->addAttachment('attachment'); // Add attachments
$mail->isHTML(true);
\t $mail->addAddress('[email protected]', 'Website'); // Add a recipient
$result = $mail->Send(); \t \t // Send!
\t $message = $result ? 'Successfully Sent!' : 'Sending Failed!';
\t unset($mail);
}
?>
<html>
<head>
<title>Contact Form</title>
</head>
<body>
\t \t \t \t \t
\t \t <div style="margin: 100px auto 0;width: 300px;">
\t \t \t <h3>Contact Form</h3>
\t \t \t <form name="form1" id="form1" action="" method="post">
\t \t \t \t \t <fieldset>
\t \t \t \t \t <input type="text" name="fullname" placeholder="Full Name" />
\t \t \t \t \t <br />
\t \t \t \t \t <input type="text" name="subject" placeholder="Subject" />
\t \t \t \t \t <br />
\t \t \t \t \t <input type="text" name="phone" placeholder="Phone" />
\t \t \t \t \t <br />
\t \t \t \t \t <input type="text" name="emailid" placeholder="Email" />
\t \t \t \t \t <br />
\t \t \t \t \t
\t \t \t \t \t
\t \t \t \t \t <input type="file" name="attachment" id="attachment" >
\t \t \t \t \t <br /> \t
\t \t \t \t \t
\t \t \t \t \t <textarea rows="4" cols="20" name="comments" placeholder="Comments"></textarea>
\t \t \t \t \t <br />
\t \t \t \t \t <input type="submit" name="submit" value="Send" />
\t \t \t \t \t </fieldset>
\t \t \t </form>
\t \t \t <p><?php if(!empty($message)) echo $message; ?></p>
\t \t </div>
\t \t \t \t \t
</body>
</html>
探し
は、単にファイルの一時パスを取得しますこのように添付ファイルとして使用してください。$ attachment = $ _FILES ['attachment'] ['tmp_name'];あなたのフォームタグにenctype = "multipart/form-data"を追加してください – sunilwananje
以下の回答を参照してください – sunilwananje
このコードは使用されているメールは送信されません送信に失敗しました!メッセージが来る –