2016-04-12 11 views
0

ses dosyası eklemek:PHP ben ses eki göndermek için aşağıdaki SMTP posta kodu kullanıyorum email

<?php 

session_start(); 

$title = $_POST['title']; 
$first_name = $_POST['name']; 
$last_name = $_POST['lastname']; 
$email_from = $_POST['email']; 
$scaptcha = strtolower($_POST['scaptcha']); 
if ($scaptcha != $_SESSION['captcha']) { 
    echo 'You have entered wrong captcha'; 
    exit(0); 
} 

require('./class.phpmailer.php'); 

function clean_string($string) { 
    $bad = array("content-type", "bcc:", "to:", "cc:", "href"); 
    return str_replace($bad, "", $string); 
} 

$email_message = ""; 
$email_message .= "Title: "  . clean_string($title)  . "\n"; 
$email_message .= "First Name: " . clean_string($first_name) . "\n"; 
$email_message .= "Last Name: " . clean_string($last_name) . "\n"; 
$email_message .= "Email: "  . clean_string($email_from) . "\n"; 

$allowedExts = array("mp3","wav","dss"); 
$temp = explode(".", $_FILES["file"]["name"]); 
$extension = end($temp); 
if ((($_FILES["file"]["type"] == "audio/mpeg")) && in_array($extension, $allowedExts)) { 
    if ($_FILES["file"]["error"] > 0) { 
     echo "<script>alert('Error: " . $_FILES["file"]["error"] . "')</script>"; 
    } else { 
     $d = 'Audio/Uploads/'; 
     $de = $d . basename($_FILES['file']['name']); 
     move_uploaded_file($_FILES["file"]["tmp_name"], $de); 
     $fileName = $_FILES['file']['name']; 
     $filePath = $_FILES['file']['tmp_name']; 
    } 
} else { 
    echo "<script>alert('Invalid file')</script>"; 
} 

$headers = 'From: ' . $email_from . "\r\n" . 
      'Reply-To: ' . $email_from . "\r\n" . 
      'X-Mailer: PHP/' . phpversion(); 
$mail = new PHPMailer(); 
$mail->IsSMTP(); 
$mail->SMTPDebug = 0; 
$mail->Debugoutput = 'html'; 
$mail->Host = "smtp.gmail.com"; 
$mail->Port = 25; 
$mail->SMTPAuth = true; 
$mail->Username = "[email protected]"; 
$mail->Password = "*****"; 
$mail->SetFrom($email_from, $first_name . ' ' . $last_name); 
//$mail->AddReplyTo('[email protected]','First Last'); 
$mail->AddAddress('[email protected]', 'Saravana'); 
$mail->Subject = 'New audio file received'; 
$mail->MsgHTML($email_message); 
$mail->AltBody = 'This is a plain-text message body'; 
$mail->AddAttachment($_FILES['file']['tmp_name'], $_FILES['file']['name']); 

if (!$mail->Send()) { 
    echo "<script>alert('Mailer Error: " . $mail->ErrorInfo . "')</script>"; 
} else { 
    echo "<script>alert('Your request has been submitted. We will contact you soon.')</script>"; 
    Header('Location: contact.php'); 
} 

?> 

Bunu düzeltmek için bana yardım edin. Bunu bir haftadan fazla süredir deniyorum. Hala anlamadım. Ben de PHP postacı denedim. Bu da çalışmıyor.

GÜNCELLEME: Ben şu hatayı alıyorum:

Mailer Error: The following From address failed: [email protected] : Called MAIL FROM without being connected,

+0

Sorun şu satırda: '$ mail-> AddAttachment ($ _ FILES ['file'] ['tmp_name'], $ _FILES ['file'] ['name']);' – Jer

+0

Well..It olacak 'PHPMailer' kullanmak için gerçekten iyi bir uygulama olmak İşte bağlantı: https://github.com/PHPMailer/PHPMailer –

+0

Kullanılıyor - $ mail = yeni PHPMailer(); – weaveoftheride

cevap

0

satır içi eki yerine mesajında ​​ses dosyası bağlantı göndermek.

$ mail-> AddAttachment yöntemi satır içi ek için kullanılır. Dosya şifreleme ve dosya boyutu nedeniyle, maksimum sunucu ses, video veya zip dosyalarının satır içi ekini göndermesine izin vermez.

0

Well..It en PHPMailer kullanarak .Here kod iken bir şey takmak için gerçekten çok kolay:

PHPMailer Bağlantı:

$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 

:https://github.com/PHPMailer/PHPMailer

Sen gibi ekleri ekleyebilir Burada tam kodu:

<?php 
require 'PHPMailerAutoload.php'; 

$mail = new PHPMailer; 

//$mail->SMTPDebug = 3;        // Enable verbose debug output 

$mail->isSMTP();          // Set mailer to use SMTP 
$mail->Host = 'smtp1.example.com;smtp2.example.com'; // Specify main and backup SMTP servers 
$mail->SMTPAuth = true;        // Enable SMTP authentication 
$mail->Username = '[email protected]';     // SMTP username 
$mail->Password = 'secret';       // SMTP password 
$mail->SMTPSecure = 'tls';       // Enable TLS encryption, `ssl` also accepted 
$mail->Port = 587;         // TCP port to connect to 

$mail->setFrom('[email protected]', 'Mailer'); 
$mail->addAddress('[email protected]', 'Joe User');  // Add a recipient 
$mail->addAddress('[email protected]');    // Name is optional 
$mail->addReplyTo('[email protected]', 'Information'); 
$mail->addCC('[email protected]'); 
$mail->addBCC('[email protected]'); 

$mail->addAttachment('/var/tmp/file.tar.gz');   // Add attachments 
$mail->addAttachment('/tmp/image.jpg', 'new.jpg'); // Optional name 
$mail->isHTML(true);         // Set email format to HTML 

$mail->Subject = 'Here is the subject'; 
$mail->Body = 'This is the HTML message body <b>in bold!</b>'; 
$mail->AltBody = 'This is the body in plain text for non-HTML mail clients'; 

if(!$mail->send()) { 
    echo 'Message could not be sent.'; 
    echo 'Mailer Error: ' . $mail->ErrorInfo; 
} else { 
    echo 'Message has been sent'; 
} 
+0

Bu kodu denedim.Bu hatayı alma --- Mesaj Gönderilmemelidir.Mailer Hatası: Aşağıdaki Kimden adresi başarısız oldu: [email protected]: MAIL FROM komutu başarısız oldu, Kimlik Doğrulama Gerekli. Daha fazla bilgi edinmek için https://support.google.com/mail/answer/14257 a22sm42385348pfj.2 - gsmtp, 530,5.5.1 –

+0

@saravananam: Kodunuz işe yarayabilir gibi görünüyor, ancak giriş yapmakta sorun yaşıyorsanız gmail hesabın ..! –

+0

evet. Oturum açma girişiminin engellendiğini belirten bir e-posta aldım. Lütfen bunu nasıl düzelteceğimi söyler misiniz? –

İlgili konular