-1

*メールの送信に問題があります。このスクリプトは localhost では効果的に機能しますが、サーバーでは機能しません 助けてください localhost と他のサーバーでのメール機能の処理に違いはありますか *

<?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 = "mohammed_habibphp@yahoo.com"; 

$RecipientName = "mohammed habib";

$SenderEmail = $email; 

$SenderName = $name;

$subject = "coding";

$cc = "alice@example.com, bob@example.com"; 

$bcc = "johndoe@example.com";


// 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);
}

?>  
4

1 に答える 1

0

PHP 4.2.3+ ではsafe_modeで 4 番目と 5 番目のパラメータが無効になり、mail() 関数を使用すると警告メッセージが表示され、FALSE が返されます。

つまり、サーバーでsafe_modeが有効になっている可能性があります。そして、あなたは4番目のパラメータを使用しています:

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

また、サーバーの sendmail が正しく設定されていないか、まったくインストールされていない可能性もあります。phpinfo()有効/登録されているかどうかを確認します。他のすべてが失敗した場合は、Web サーバー ホストに電話するか、チケットを送信してください。

于 2013-03-14T23:18:39.393 に答える