0

以下のコードで生成されたページからメールを送信すると。次の問題が発生します。

テキスト領域に入力して添付ファイルを追加すると、受信されるメッセージは本文 (テキスト領域) 以外のすべてになります。

添付ファイルを追加しないと正常に動作しますが、明らかに添付ファイルを追加する必要があります。

以下のコードは、ページの完全なコードです。かなりの量で申し訳ありませんが、どこが間違っているのか見当がつかないので、その一部だけを強調することはできません. この投稿に返信してくれたすべての人に感謝します。

メールライブラリ: Swiftmailer、PHP メーラー Zend_Mail。私はそれらを機能させようとしましたが、理解できませんでした。簡単なチュートリアルは実行可能でしたが、DB と添付ファイルからデータを取得すると、絶望的になりました。私はそれが可能だと確信していますが、どうして私にはわかりません。

質問: 添付ファイルとテキストエリアが送信されないのはなぜですか。

verzenden.php

 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
 <link rel="stylesheet" type="text/css" href="css/overzichten.css">
 <link rel="stylesheet" type="text/css" href="css/offerte_facturen.css">
 <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js">     </script>
 <style>.hidden{display: none;}</style>
 </head>
 <body>
 <?php
 // Load Joomla! configuration file
 require_once('../../../configuration.php');
 // Create a JConfig object
 $config = new JConfig();
 // Get the required codes from the configuration file
 $server = $config->host;
 $username   = $config->user;
 $password   = $config->password;
 $database = $config->db;
 // Connect to db
 $con = mysqli_connect($server,$username,$password,$database);
 if (!$con){
die('Could not connect: ' . mysqli_error($con));
 }
 mysqli_select_db($con,$database);

 // Check whether the value for id is transmitted
 if (isset($_GET['id'])) {

 // Put the value in a separate variable
 $id = $_GET['id'];

 // Query the database for the details of the chosen id
 $result = mysqli_query($con,"SELECT * FROM cypg8_overzicht WHERE id = $id");

 // Check result
 // This shows the actual query sent to MySQL, and the error. Useful for debugging.
 if (!$result) {
 $message = "Invalid query: " . mysqli_error($result) . "\n";
 $message .= "Whole query: " . $query;
 die($message);
 }

 // Use result
 // Attempting to print $result won't allow access to information in the resource
 // One of the mysql result functions must be used
 // See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(),etc.
 while ($row = mysqli_fetch_assoc($result)) {
 // ID van de offerte/factuur dit gegeven is verborgen van het formulier
 echo "<input type='text' name='id' id='id' style='display:none;' value='" .$row['id'].      "'>";

 // Start formulier
 echo "<form action='verzenden_script.php' method='post' name='form1' id='form1'      enctype='multipart/form-data'>";
 echo "<div>klantemail<input type='textbox' name='klantemail'   value='".$row['email']."'></div>";
 echo "<div>dealeremail<input type='textbox'    name='dealeremail' value='".$row['dealeremailadres']."'></div>";
 echo "<div><select name='offertefactuur'>";
 echo "<option value='Offertenummer'>Offerte</option>";
 echo "<option value='Factuurnummer'>Factuur</option>";
 echo "</select></div>";
 echo "<div>formuliernummer<input type='textbox'    name='formuliernummer' value='".$row['formuliernummer']."'></div>";
 echo "<div><li>Bedankt voor uw factuuraanvraag!</li></div>";
 echo "<div>berichtonderwerp<input type='textbox' name='berichtonderwerp'   value=''>     </div>";
 echo "<div><li>Bedankt voor uw factuur aanvraag. In de bijlage kunt u deze factuur bekijken.</li></div>";
 echo "<div>bericht<textarea    name='bericht'></textarea></div>";
 echo "<div><input type='file' name='fileAttach' value='Zoeken'></div>";
 echo "<div><input type='submit' name='Submit' value='Verzenden'></div>";
 echo "</form>";

 }
 } else {
 die("No valid id specified!");
 }
 ?>
 </body>

verzenden_script.php

<?php
$naar = $_POST["klantemail"];
$naar2 = $_POST["dealeremail"];
$naar3 = 'dealer@loginsecure.nl';
$formuliernummer = $_POST["formuliernummer"];
$offertefactuur = $_POST["offertefactuur"];
$berichtonderwerp = $_POST["berichtonderwerp"];
$bericht = $_POST["bericht"];

//define the receiver of the email 
$to = $naar.",".$naar2.",".$naar3; 
//define the subject of the email 
$subject = $berichtonderwerp ."|". $offertefactuur .":". $formuliernummer; 
//create a boundary string. It must be unique 
//so we use the MD5 algorithm to generate a random hash 
$random_hash = md5(date('r', time())); 
//define the headers we want passed. Note that they are separated with \r\n 
$headers = "From: $cc\r\nReply-To: $cc"; 
//add boundary string and mime type specification 
$headers .= "\r\nContent-Type: multipart/mixed; boundary=\"PHP-mixed-".$random_hash."\""; 
//read the atachment file contents into a string,
//encode it with MIME base64,
//and split it into smaller chunks
if($_FILES["fileAttach"]["name"] != "")
{
    $strFilesName = $_FILES["fileAttach"]["name"];
    $strContent = chunk_split(base64_encode(file_get_contents($_FILES["fileAttach"]["tmp_name"]))); 
    $headers .= "--".$strSid."\n";
    $headers .= "Content-Type: application/octet-stream; name=\"".$strFilesName."\"\n"; 
    $headers .= "Content-Transfer-Encoding: base64\n";
    $headers .= "Content-Disposition: attachment; filename=\"".$strFilesName."\"\n\n";
    $headers .= $strContent."\n\n";
}
//define the body of the message. 
ob_start(); //Turn on output buffering 
?> 
--PHP-mixed-<?php echo $random_hash; ?>  
Content-Type: multipart/alternative; boundary="PHP-alt-<?php echo $random_hash; ?>" 

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/plain; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<?php echo $berichtonderwerp ?>
<?php echo $bericht ?>

--PHP-alt-<?php echo $random_hash; ?>  
Content-Type: text/html; charset="iso-8859-1" 
Content-Transfer-Encoding: 7bit

<h2><?php echo $berichtonderwerp ?></h2> 
<p><?php echo $bericht ?></p> 

--PHP-alt-<?php echo $random_hash; ?>-- 

--PHP-mixed-<?php echo $random_hash; ?>-- 

<?php 
//copy current buffer contents into $message variable and delete current output buffer 
$message = ob_get_clean(); 
//send the email 
$mail_sent = @mail( $to, $subject, $message, $headers ); 
//if the message is sent successfully print "Mail sent". Otherwise print "Mail failed" 
echo $mail_sent ? "Mail sent" : "Mail failed"; 
?>

編集 1

私は何度も読んでいますが、多くの人が同じ問題を抱えています。その部分についていくつかの提案があります

--PHP-alt-<?php echo $random_hash; ?>
--PHP-alt-<?php echo $random_hash; ?>--

間違っていましたが、確認しましたが、問題がそこにあるとは思いません。しかし、もう少し読んだ後、問題はにあると思います。\nそれらをに変更する必要があることを願っています\r\n。残念ながらうまくいきませんでした。それは一種の不自由な試行錯誤でした。しかし、挑戦しない人は決して成功しません。

4

1 に答える 1

1

これが機能しなかったので、Joomla 拡張機能である Chronoforms に切り替えました。これは簡単であるだけでなく、はるかに高速であることがわかりました。上記の質問を修正するための適切な解決策を考え出すことを皆さんに勧めます。しかし、それまでの間、クロノフォームを使用する立場にあるとき. 私はそれをすることを提案します。

于 2013-10-25T16:00:14.177 に答える