2013-10-21 115 views
0

当我通过下面的代码生成的页面发送电子邮件。我遇到以下问题。附件或邮件显示,但不是在电子邮件中都显示

当我填写文本区域并添加一个附件而不是接收到的消息是除主体(这是文本区域)之外的所有内容。

当我不添加附件,然后它工作正常,但显然附件需要添加。

下面的代码是页面的完整代码。对不起,这是相当多的,但我不知道它出错的地方,所以我不能突出显示它的一部分。感谢回复此帖子的所有人。

电子邮件:Swiftmailer,PHP邮件程序Zend_Mail。我一直试图让他们工作,但我无法弄清楚。简单的教程可行,但从数据库和文件附件中获取内容变得毫无希望。我相信这是可能的,但我怎么不知道。

问题:为什么它不发送附件和textarea。

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 = '[email protected]'; 
$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。太糟糕了,它没有奏效。这是一个蹩脚的尝试和错误。但谁不尝试永远不会成功。

回答

1

我没有得到这个工作,所以我切换到Chronoforms这是一个Joomla扩展,我发现这不仅更容易,而且更快。我邀请每个人提出一个适当的解决方案来解决上述问题。但在此期间,当你处于使用时计的位置时。我建议去做。

相关问题