2013-03-14 6 views
-1

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

<?php 
session_start(); 
error_reporting(E_ALL & ~E_NOTICE); 

/** 
* this function is made to upload multiple files 
*@param string $file (input name) 
*@return nothing 
*/ 
function upload($file) 
{ 
    for($i=0; $i<count($_FILES[$file]['name']); $i++) { 
    //Get the temp file path 
    $file_name = $_FILES[$file]['name'][$i]; 
    $type = $_FILES[$file]['type'][$i]; 
    $tmpFilePath = $_FILES[$file]['tmp_name'][$i]; 
    //Make sure we have a filepath 
    if ($tmpFilePath != ""){ 
    //Setup our new file path 
    global $newFilePath; 
    $newFilePath = "uploadFiles/" . $_FILES[$file]['name'][$i]; 
    global $files; 
    $files[] = array($newFilePath.':'.$type.':'.$file_name); 
    //echo $files; 


    //Upload the file into the temp dir 
    if(move_uploaded_file($tmpFilePath, $newFilePath)) { 

    echo "تم رفع الملفات بنجاح"; 

    } 
    else{ 
     echo "حدث خطا فى رفع الملفات"; 
    } 
    } 
} 
} 






if($_POST['contact']) 
{ 



    if($_POST['name'] && $_POST['email'] && $_POST['phone'] && $_POST['others'] && $_FILES['img']) 
    { 
     $name = $_POST['name']; 
     $email = $_POST['email']; 
     $phone = $_POST['phone']; 
     $others = $_POST['others']; 
     $others = implode(" and ", $others); 
     upload("img"); 
     foreach ($files as $index => $file) { 
    foreach ($file as $value) { 
    $a[] = $value; 
    } 
} 
} 
    else 
    { 
     $_SESSION['message'] = "please fill all require fields"; 
     header('Location: contact.php'); 
    } 
} 



?> 

<?php 
$RecipientEmail = "[email protected]"; 

$RecipientName = "mohammed habib"; 

$SenderEmail = $email; 

$SenderName = $name; 

$subject = "coding"; 

$cc = "[email protected], [email protected]"; 

$bcc = "[email protected]"; 


// For HTML 
$type = "HTML"; 
// For plain text 
//$type = "plain"; 


$message ="<b>customer name</b>: ".$name. 


"<br /><b>email</b>: ".$email. 


"<br /><b>phone</b>: ".$phone. 


"<br /><b>others</b>: ".$others; 





// For normal leave it blank 
$priority = "high"; 

$attachments =$a; 


$sent = Email($RecipientEmail, 
       $RecipientName, 
       $SenderEmail, 
       $SenderName, 
       $cc, 
       $bcc, 
       $subject, 
       $message, 
       $attachments, 
       $priority, 
       $type); 

echo $sent ? "It worked!!" : "It didn't work"; 
//^This is used to test if it worked 

// This work is licensed under a Creative Commons Attribution-NonCommercial 3.0 Unported License 

function Email($remail, $rname, $semail, $sname, $cc, $bcc, $subject, $message, $attachments, $priority, $type) { 

// Checks if carbon copy & blind carbon copy exist 
if($cc != null){$cc="CC: ".$cc."\r\n";}else{$cc="";} 
if($bcc != null){$bcc="BCC: ".$bcc."\r\n";}else{$bcc="";} 

// Checks the importance of the email 
if($priority == "high"){$priority = "X-Priority: 1\r\nX-MSMail-Priority: High\r\nImportance: High\r\n";} 
elseif($priority == "low"){$priority = "X-Priority: 3\r\nX-MSMail-Priority: Low\r\nImportance: Low\r\n";} 
else{$priority = "";} 

// Checks if it is plain text or HTML 
if($type == "plain"){$type="text/plain";}else{$type="text/html";} 

// The boundary is set up to separate the segments of the MIME email 
$boundary = md5(@date("Y-m-d-g:ia")); 

// The header includes most of the message details, such as from, cc, bcc, priority etc. 
$header = "From: ".$sname." <".$semail.">\r\nMIME-Version: 1.0\r\nX-Mailer: PHP\r\nReply-To: ".$sname." <".$semail.">\r\nReturn-Path: ".$sname." <".$semail.">\r\n".$cc.$bcc.$priority."Content-Type: multipart/mixed; boundary = ".$boundary."\r\n\r\n";  

// The full message takes the message and turns it into base 64, this basically makes it readable at the recipients end 
$fullmessage = "--".$boundary."\r\nContent-Type: ".$type."; charset=UTF-8\r\nContent-Transfer-Encoding: base64\r\n\r\n".chunk_split(base64_encode($message)); 

// A loop is set up for the attachments to be included. 
if($attachments != null) { 
    foreach ($attachments as $attachment) { 
    $attachment = explode(":", $attachment); 
    print_r($attachment); 

    $fullmessage .= "--".$boundary."\r\nContent-Type: ".$attachment[1]."; name=\"".$attachment[2]."\"\r\nContent-Transfer-Encoding: base64\r\nContent-Disposition: attachment\r\n\r\n".chunk_split(base64_encode(file_get_contents($attachment[0]))); 
    } 
} 

// And finally the end boundary to set the end of the message 
$fullmessage .= "--".$boundary."--"; 

return mail($rname."<".$remail.">", $subject, $fullmessage, $header); 
} 

?> 
+0

, пожалуйста, эта проблема вызвала у меня головную болью –

+1

Опишите, не работает. В какой момент это происходит? –

+0

Вы должны описать фактическую проблему более подробно. Отображается ли ошибка? Какая функция не работает? – mhu

ответ

0

В PHP 4.2.3+ 4-й и 5-й параметры отключены в safe_mode, а функция mail() выдает предупреждающее сообщение и возвращает FALSE при использовании.

Другими словами, ваш сервер, вероятно, имеет safe_mode включен. И вы используете 4-й параметр:

return mail($rname."<".$remail.">", $subject, $fullmessage, $header);

Может быть также небольшая вероятность того, что Sendmail сервера не настроен должным образом или не установлен вообще. Проверьте phpinfo(), чтобы узнать, включено ли оно/зарегистрировано. Если все остальное не удается вызвать хост вашего веб-сервера или отправить билет.

+0

Я вам очень благодарен :) хозяин в безопасном настроении спасибо –

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