我正在開發一個使用PHP的小型電子郵件應用程序,用於發送電子郵件,我使用PHPMailer,所有功能除了形成一個「附件」外。附件只是沒有通過發送的電子郵件。我嘗試了許多不同的方法來解決這個問題,但我有我現在相信已經不遠了一個工作秩序....未通過電子郵件發送的附件
我會後,與附件程序處理的代碼小零件....
HTML代碼:
<form action="php/smtp_saved.php" method="post">
<input type="file" name="attach" id="attach" />
</form>
PHP代碼:
if ($_POST['action'] == 'Send') {
if (preg_match('<,>', $email['recipient'])) {
$address = explode(',', $email['recipient']);
if (sizeof($address) < 19) {
foreach ($address as $recipient) {
$save = new saveSaved();
$save->save($_SESSION['user'], $email['recipient'], gmdate('Y-m-d H:i:s', strtotime ('+1 hour')), $_SESSION['delete'],$email['HTML']);
require_once('../PHPMailer/PHPMailerAutoload.php');
require_once('../PHPMailer/class.smtp.php');
$mail = new PHPMailer;
$mail->isSMTP(); // Set mailer to use SMTP
$mail->Host = 'smtp.gmail.com'; // Specify main and backup server
$mail->Port = '465';
$mail->SMTPAuth = true; // Enable SMTP authentication
$mail->Username = $_SESSION['user']; // SMTP username
$mail->Password = $_SESSION['pass']; // SMTP password
$mail->SMTPSecure = 'ssl'; // Enable encryption, 'ssl' also accepted
$mail->From = $_SESSION['user'];
$mail->FromName = 'OneTwoTrade';
//$mail->addAddress($email['recipient']); // Add a recipient
//$mail->addAddress('[email protected]'); // Name is optional
$mail->addAddress(trim($recipient));
if (preg_match('<,>', $email['cc'])) {
$cc = explode(',', $email['cc']);
if (sizeof($cc) < 9) {
foreach ($cc as $carbonC) {
$mail->addCC($carbonC);
}
} else {
exit ('Max 10 Recipients Per Email');
}
} else {
$mail->addCC($email['cc']);
}
//$mail->addBCC('[email protected]');
$mail->WordWrap = 50; // Set word wrap to 50 characters
if(is_uploaded_file($_FILES['attach']['tmp_name'])) {
$file = $_FILES['attach']['name'];
$mail->AddAttachment($file);
}
/*
if(isset($_FILES['uploaded_file']) && $_FILES['uploaded_file']['error'] == UPLOAD_ERR_OK){
$mail->addAttachment($_FILES['uploaded_file']['tmp_name'],
$_FILES['uploaded_file']['name']);
}
*/
// Add attachments
//$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name
$mail->isHTML(true); // Set email format to HTML
$mail->Subject = $email['subject'];
$mail->Body = $email['HTML'];
//$mail->AltBody = 'This is the body in plain text for non-HTML mail clients';
//$mail->SMTPDebug =1;
if (!$mail->send()) {
header("Location: ../saved_emails.php?error2");
//echo 'Message could not be sent.';
//echo 'Mailer Error: ' . $mail->ErrorInfo;
exit;
}
}
}
}
有人可以幫我發現了一個錯誤或者直接到的信息體面源....?
謝謝我已經試過這個,但沒有任何區別,仍然發送沒有附件的電子郵件,也許我必須specyfie文件擴展名或大小...? – user3669523
你可以發佈你有這個操作的所有代碼嗎?我必須先看看發生什麼事 – zkanoca
好吧我添加了整個PHP Mailer類看看 – user3669523