2014-05-28 2 views
0

Я пытаюсь создать форму заказа, которая по завершении перейдет на страницу order.php (отправляет электронное письмо), где вы затем передаете на paypal. Все работало нормально, пока я не попытался добавить вложения, когда я добавил код для вложения, письмо больше не отправляется.PHP Форма заказа - электронная почта с приложением

<?php 

$to = 'hidden' ; 
$from = $_REQUEST['email'] ; 
$name = $_REQUEST['name'] ; 
$headers = "From: $from"; 
$subject = "Distinctive Writers - Contact Form"; 
$tprice = $_REQUEST['tprice'] ; 

$fields = array(); 
$fields{"name"} = "name"; 
$fields{"email"} = "email"; 
$fields{"number"} = "number"; 
$fields{"subject"} = "subject"; 
$fields{"doctype"} = "doctype"; 
$fields{"spec"} = "spec"; 
$fields{"grade"} = "grade"; 
$fields{"days"} = "days"; 
$fields{"due"} = "due"; 
$fields{"pages"} = "pages"; 
$fields{"price"} = "price"; 

$mime_boundary="==Multipart_Boundary_x".md5(mt_rand())."x"; 

$tmp_name = $_FILES['filename']['tmp_name']; 
$type = $_FILES['filename']['type']; 
$file_name = $_FILES['filename']['name']; 
$size = $_FILES['filename']['size']; 

if (file_exists($tmp_name)){ 

    // Check to make sure that it is an uploaded file and not a system file 
    if(is_uploaded_file($tmp_name)){ 

    // Now Open the file for a binary read 
    $file = fopen($tmp_name,'rb'); 

    // Now read the file content into a variable 
    $data = fread($file,filesize($tmp_name)); 

    // close the file 
    fclose($file); 

    // Now we need to encode it and split it into acceptable length lines 
    $data = chunk_split(base64_encode($data)); 
} 

// Now we'll build the message headers 
    $headers = "From: $from\r\n" . 
    "MIME-Version: 1.0\r\n" . 
    "Content-Type: multipart/mixed;\r\n" . 
    " boundary=\"{$mime_boundary}\""; 

    // Now we'll insert a boundary to indicate we're starting the attachment we have to specify the content type, file name, and disposition as an attachment, then add the file content and set another boundary to indicate that the end of the file has been reached 
    $message .= "--{$mime_boundary}\n" . 
    "Content-Type: {$type};\n" . 
    " name=\"{$file_name}\"\n" . 
    //"Content-Disposition: attachment;\n" . 
    //" filename=\"{$fileatt_name}\"\n" . 
    "Content-Transfer-Encoding: base64\n\n" . 
    $data . "\n\n" . 
    "--{$mime_boundary}--\n"; 


$body = "We have received the following information:\n\n"; foreach($fields as $a => $b){ $body .= sprintf("%20s: %s\n",$b,$_REQUEST[$a]); } 

$headers2 = "From: [email protected]"; 
$subject2 = "Thank you for contacting us"; 
$autoreply = "Thank you for contacting us. Somebody will get back to you as soon as possible, usualy within 48 hours. If you have any more questions, please consult our website at www.oursite.com"; 

if($from == '') {print "You have not entered an email, please go back and try again";} 
else { 
if($name == '') {print "You have not entered a name, please go back and try again";} 
else { 
$send = mail($to, $subject, $body, $headers, $message); 
$send2 = mail($from, $subject2, $autoreply, $headers2); 

} 
} 

if(!mail($to, $subject, $body, $headers, $message)){ 
print "ERROR!!"; 
} 
} 
?> 
+1

Я бы предложил использовать библиотеку, такую ​​как PHPMailer, потому что создание заголовков vaild для любого почтового клиента - headbanging! –

+0

Я не знал, подходит ли PHPMailer, потому что я посмотрел пример кода и показал заранее определенный файл (а не выгрузку по выбору пользователя). «$ mail-> AddAttachment (« images/phpmailer.gif »); // вложение« – user69200

+0

$ mail-> AddAttachment («$ file»); Прочтите примеры ... –

ответ

0

Я рекомендую PHPMailer тоже, как упомянуто ПК-шутер

, то вы можете использовать

$mail = new PHPMailer(); 

, то вы можете использовать либо один из этих двух

$mail->AddStringAttachment($string,$filename) 
$mail->AddAttachment($path); 

что-то имейте в виду, что-то еще может блокировать электронную почту. если функция почты возвращает TRUE, тогда почта была отправлена.

Смежные вопросы