1

PHPを使用してメールを送信するときに小さな問題があります。フォームを送信すると、データと添付ファイル付きのメールが届きますが、添付ファイルは jung データ (文字列形式) として送信されます。ここに私のコードがあります

誰でも助けることができますか?

    <?php
session_start(); // start up your PHP session!
// Obtain file upload vars
$file_name = $_FILES['attach']['name'];
$temp_name = $_FILES['attach']['tmp_name'];
$file_type = $_FILES['attach']['type'];
// Obtain file upload vars
$file_name2 = $_FILES['attach2']['name'];
$temp_name2 = $_FILES['attach2']['tmp_name'];
$file_type2 = $_FILES['attach2']['type'];
// Obtain file upload vars
$file_name3 = $_FILES['attach3']['name'];
$temp_name3 = $_FILES['attach3']['tmp_name'];
$file_type3 = $_FILES['attach3']['type'];

// message
$subject = "New Message";
/* Send Values to email in HTML format*/

$message  = '<html><body>';
$message .= '<h2>Please see the below details</h2>';
$message .= '<table rules="all" style="border-color: #666;" width="50%" cellpadding="10">';
$message .= "<tr style='background: #eee;'><td><strong>Title:</strong> </td><td>" . strip_tags($_POST['title']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>First Name:</strong> </td><td>" . strip_tags($_POST['fname']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Middle Name:</strong> </td><td>" . strip_tags($_POST['mname']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Last Name:</strong> </td><td>" . strip_tags($_POST['lname']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Street Name:</strong> </td><td>" . strip_tags($_POST['saddress']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Apartment / Suite / Other:</strong> </td><td>" . strip_tags($_POST['oaddress']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>City:</strong> </td><td>" . strip_tags($_POST['city']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>State:</strong> </td><td>" . strip_tags($_POST['state']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Zip Code:</strong> </td><td>" . strip_tags($_POST['zip']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Cell Phone Number:</strong> </td><td>" . strip_tags($_POST['cellphone']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Home Phone:</strong> </td><td>" . strip_tags($_POST['homephone']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Office Phone:</strong> </td><td>" . strip_tags($_POST['officephone']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Prefered Call Time:</strong> </td><td>" . strip_tags($_POST['calltime']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Personal E-mail ID:</strong> </td><td>" . strip_tags($_POST['pemail']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Office E-mail ID:</strong> </td><td>" . strip_tags($_POST['oemail']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Account Type:</strong> </td><td>" . strip_tags($_POST['acctype']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Comments:</strong> </td><td>" . strip_tags($_POST['comments']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Primary ID Proof:</strong> </td><td>" . strip_tags($_POST['primaryid']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Secondary ID Proof:</strong> </td><td>" . strip_tags($_POST['secondaryid']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Other ID Proof:</strong> </td><td>" . strip_tags($_POST['alternateid']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Funding Option:</strong> </td><td>" . strip_tags($_POST['fundingoption']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Bank Account Number:</strong> </td><td>" . strip_tags($_POST['pbaccnumber']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Bank Account Type:</strong> </td><td>" . strip_tags($_POST['eacctype']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Funding Bank Account Number:</strong> </td><td>" . strip_tags($_POST['fbankaccnumber']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Funding Bank ABN Number:</strong> </td><td>" . strip_tags($_POST['fbankabanumber']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Funding Bank Account Type:</strong> </td><td>" . strip_tags($_POST['fbcctype']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Funding Amount:</strong> </td><td>" . strip_tags($_POST['famt']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I agree to share the information to pull Credit reports, CHEX system reports etc. for verification</strong> </td><td>" . strip_tags($_POST['iagree']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree Online Banking & Paperless Statements</strong> </td><td>" . strip_tags($_POST['agronlinebank']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree Fee Schedule</strong> </td><td>" . strip_tags($_POST['agrFee']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree Online Banking Fraud </strong> </td><td>" . strip_tags($_POST['agronlinebankfraud']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree Overdraft Notice</strong> </td><td>" . strip_tags($_POST['agroverdraft']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree EFT Agreement</strong> </td><td>" . strip_tags($_POST['AgreeEFT']) . "</td></tr>";

$message .= "<tr style='background: #eee;'><td><strong>I certify that I am an American citizen</strong> </td><td>" . strip_tags($_POST['citizenConfirm']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Truth in Savings</strong> </td><td>" . strip_tags($_POST['TruthSavings']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>I Agree you acknowledge you have read and accept the terms and conditions as described above </strong> </td><td>" . strip_tags($_POST['DConfirm']) . "</td></tr>";
$message .= "<tr style='background: #eee;'><td><strong>Would you like to apply for another Deposit account?</strong></td><td>" . strip_tags($_POST['appanotherdepacc']). "</td></tr>";
$message .= "</table>";
$message .= "</body></html>";

/* recipients */
$to = "xyz@abc.com";


// --------------------------------------

$headers = "From:info@abc.com";      
$headers .= "\r\nReply-To:info@abc.com"; 
$headers .= "\r\nContent-Type: text/html; charset=UTF-8";
$headers .= "\r\nMIME-Version: 1.0";

// things you need
$file = $temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid = md5(uniqid(time()));


// declaring we have multiple kinds of email
$headers .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$headers .= "This is a multi-part message in MIME format.\r\n";

// html text part
$headers .= "–".$uid."\r\n";
$headers .= "Content-type:text/html; charset=iso-8859-1\r\n";
$headers .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$headers .= $message."\r\n\r\n";

//file attachment
$headers .= "–" .$uid. "\r\n";
$headers .= "Content-Type: ".$file_type."; name=\"".$file_name."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";

//file attachment 2
$headers .= "–" .$uid. "\r\n";
$headers .= "Content-Type: ".$file_type2."; name=\"".$file_name2."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$file_name2."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";

//file attachment 3
$headers .= "–" .$uid. "\r\n";
$headers .= "Content-Type: ".$file_type3."; name=\"".$file_name3."\"\r\n";
$headers .= "Content-Transfer-Encoding: base64\r\n";
$headers .= "Content-Disposition: attachment; filename=\"".$file_name3."\"\r\n\r\n";
$headers .= $content."\r\n\r\n";

// Send the message
$ok = @mail($to, $subject, "", $headers);

if ($ok) {
  echo "<p>Mail sent.</p>";
} else {
  echo "<p>Mail could not be sent. Sorry!</p>";
}
?>
4

1 に答える 1

0

ここhttp://phpmailer.worxware.com/index.php?pg=exampledbからヘルプを得ることができます。幸運を。

于 2013-02-04T07:13:38.347 に答える