问题描述
我正在使用 PHP 邮件功能发送附件文件,我想在电子邮件帐户的收件箱中显示附件文件,但是我获取与附件相关的详细信息的变量 $data 为空。请帮助我显示附件电子邮件收件箱中的文件。 下面是我的代码。
$data = chunk_split(base64_encode(file_get_contents($data))); 我在 $data 变量中获取数据。
send_mail.PHP
<?PHP
if (isset($_POST['email'])) {
$email = $_POST['email'];
$mobile = $_POST['mobile'];
$fname = '';
if(isset($_POST['fname'])){
$fname = $_POST['fname'];
}
$lname = '';
if(isset($_POST['lname'])){
$lname = $_POST['lname'];
}
$candidate_name = '';
if(isset($_POST['candidate_name'])){
$candidate_name = $_POST['candidate_name'];
}
$questions = '';
if(isset($_POST['questions'])){
$questions = $_POST['questions'];
}
$apply_for = '';
if(isset($_POST['apply_for'])){
$apply_for = $_POST['apply_for'];
}
$experience = '';
if(isset($_POST['experience'])){
$experience = $_POST['experience'];
}
$candidate_message = '';
if(isset($_POST['candidate_message'])){
$candidate_message = $_POST['candidate_message'];
}
$data = '';
if(isset($_FILES)){
$file_name = $_FILES['my_file']['name'];
$temp_name = $_FILES['my_file']['tmp_name'];
$file_type = $_FILES['my_file']['type'];
$path_parts = pathinfo($file_name);
$ext = $path_parts['extension'];
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$file = fopen($_FILES['my_file']['tmp_name'],"rb");
$data = fread($file,filesize($_FILES['my_file']['tmp_name']));
fclose($file);
//$data = chunk_split(base64_encode($data));
$data = chunk_split(base64_encode(file_get_contents($data)));
$name = $_FILES['my_file']['name'];
/* $message .= "Content-Type: {\"application/octet-stream\"};\n" . " name=\"$name\"\n" .
"Content-disposition: attachment;\n" . " filename=\"$name\"\n" .
"Content-transfer-encoding: base64\n\n" . $data . "\n\n";
$message .= "--{$mime_boundary}\n"; */
}
$body = '<html>
<head>
<Meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Cross Hudson Plastic Surgery</title>
</head>
<body>
<div style="background: #f1f1f1 none repeat scroll 0 0; display: inline-block; min-height: 100vh; width: 100%; font-size:14px;">
<div style="font-family: arial; background: #f5f5f5 none repeat scroll 0 0; border-radius: 5px; Box-sizing: border-Box; display: table; margin: 30px auto;max-width: 800px;min-width: 400px; width: 100%;">
<div style="background: #333 none repeat scroll 0 0;border-bottom: 1px solid #dfdfdf; margin-bottom: 30px; text-align: center;">
<img style=" margin: 20px 0; max-width: 267px;" src="https://www.devoint.com/images/logo.png">
</div>
<div style="margin: 0 auto; padding: 10px 50px 22px; font-size: 15px;">
<p style="color: #5f5f5f; line-height: 1.6;">Details has given below :-</p>
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Email : </b>' . $email . '
</p>
<p style="color: #5f5f5f; line-height: 1.6;">
<b>mobile Number: </b>' . $mobile . '
</p>
';
if($fname != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>First Name : </b>' . $fname . '
</p>';
}
if($lname != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Last Name : </b>' . $lname . '
</p>';
}
if($candidate_name != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Candidate Name : </b>' . $candidate_name . '
</p>';
}
if($questions != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Questions : </b>' . $questions . '
</p>';
}
if($apply_for != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Apply For : </b>' . $apply_for . '
</p>';
}
if($experience != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b>Experience : </b>' . $experience . '
</p>';
}
if($candidate_message != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b> candidate_message : </b>' . $candidate_message . '
</p>';
}
if($data != ''){
$body .= '
<p style="color: #5f5f5f; line-height: 1.6;">
<b> filename : </b>' . $name . '<br>
<b> Attachment : </b>' . $data . '
</p>';
}
$body .='
</div>
<div style="background: #333 none repeat scroll 0 0; padding: 9px 30px;text-align: center;">
<p style="color: #fff; line-height: 1.5; font-size:13px;">
copyright © ' . date("Y") . ' Devoint IT Solutions
</p>
</div>
</div>
</div>
</body>
</html>';
$to = 'email@gmail.com';
$from = 'Contact@gmail.com';
if(isset($_POST['userName'])){
$subject = "Have some questions?";
}
else{
$subject = "Candidature form";
}
//$subject = "New Contact Form Submitted";
// To send HTML mail,the Content-type header must be set
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .= "Content-Type: multipart/mixed; boundary=\"" . $semi_rand . "\"" . "\r\n";
// Additional headers
$headers .= 'To: ' . $to . "\r\n";
$headers .= 'From: ' . $from . "\r\n";
// Send the email
$page = $_SERVER['HTTP_REFERER'];
if (mail($to,$subject,$body,$headers)) {
echo '<div class="alert alert-success alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>Success!</strong>Your details has been submitted successfully! We will contact you soon.</div>';
die;
} else {
echo '<div class="alert alert-danger alert-dismissible"><a href="#" class="close" data-dismiss="alert" aria-label="close">×</a><strong>Alert!</strong> Something went wrong!</div>';
die;
}
}
?>
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)