Я делаю форму в html, в которой есть кнопка загрузки и некоторые сведения о пользователе. Я хочу отправить все детали формы вместе с файлом, загруженным от пользователя. Но он не работает. Я также отправляю код кода html и код Php. Скажи мне, где мне не хватает.File Attachment not going in mail in php
<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="style.css" />
<body>
<div class="element">
<a href="index.php"><img src="logo.gif"></a>
<br><br>
<div class="new"></div>
<center><h2>Submit Your Information below</h2></center>
<form name="registration" method="post" action="fromaction.php" enctype="mutipart/form-data" autocomplete="off">
<!-- <span class="erorr"> --->
<div class="image"></div>
<label>Name:</label>
<input id="box1" placeholder="Type here" type="text" name="Name:" required>
<br><br>
<label>Email:</label><input id="box2" placeholder="Type here" type="email" name="Email:" required >
<br>
<br>
<label>Time period in which you will join</label>
<select id ="myList" name="Time Required by user to Join the company" >
<option value="Immediate" required>Immediate</option>
<option value="Less than one month">Less than one month</option>
<option value="1 month">1 month</option>
<option value="2 months">2 months</option>
</select>
<br><br>
<label>Linkedin Link:</label>
<input type="text" id="box3" name="Linkedin ID" placeholder="https://www" required >
<br><br>
<label for="workexcel">What job responsibilities and duties do you excel at?</label>
<textarea name="At which The User is Excel in:" placeholder="Type Here.." id="add" rows="2" cols="2" maxlength="300" required></textarea>
<br><br>
<label>Tell me about a challenge or conflict you've faced at work, and how you dealt with it.</label>
<textarea name="How user dealt with challenge or conflict" placeholder="Type Here.." rows="2" cols="2" maxlength="300" required ></textarea>
<br><br>
<label for"twork">What is your greatest professional achievement?</label>
<textarea name="User Professional achievement:" placeholder="Type here.." id="twork" rows="10" cols="30" maxlength="300" required></textarea>
<br>
<br><br>
<label for="det">Tell us something about Yourself</label>
<textarea name= "Details About the user" placeholder="Type here.." id="det" rows="10" cols="30" maxlength="300" required ></textarea>
<br><br>
<label for="resume">Attach Your Resume here </label>
<input type="file" name="uploaded_file">
<br><br>
<input type="checkbox" value="Area" required> I understand that I am applying for the job which is of my Area of field.
<br>
<h1><input id="submit" type="Submit" value="Submit"></h1>
<!-- </span> -->
</form>
</div>
</body>
</head>
</html>
PHP код здесь
<?php
$c_name=$_POST['Name:']; // Contain Candidate name
$c_email=$_POST['Email:']; // Contain email
$c_time=$_POST['Time Required by user to Join the company'];
$c_linkedin=$_POST['Linkedin ID'];
$c_Excel=$_POST['At which The User is Excel in:'];
$c_challenge=$_POST['How user dealt with challenge or conflict'];
$c_professional=$_POST['User Professional achievement:'];
$c_details=$_POST['Details About the user'];
$file_name=$_FILES['uploaded_file']['name'];
$temp_name=$_FILES['uploaded_file']['tmp_name'];
$file_type=$_FILES['uploaded_file']['type'];
//get the extension of the file
$base = basename($file_name);
$extension=substr($base, strlen($base)-4,strlen($base));
$allowed_extensions=array(".doc","docx",".pdf",".zip",".png");
if(in_array($extension,$allowed_extensions)){
$from = $_POST['Email:'];
$to = "[email protected]";
$subject = "testing";
$message = "<table width='800' border='1' cellspacing='0' cellpadding='8' bordercolor='#CCCCC'>
<tr>
<td colspan='2' bgcolor='#CDD9F5'><strong>Candidate Details</strong></td>
</tr>
<tr>
<td width='168' bgcolor='#FFFFEC'><strong>Candidate Name</strong></td>
<td width='290' bgcolor='#FFFFEC'>$c_name</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>E-mail ID</strong></td>
<td bgcolor='#FFFFDD'>$c_email</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>Time required by user to Join the Company</strong></td>
<td bgcolor='#FFFFDD'>$c_time</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>Linkedin ID</strong></td>
<td bgcolor='#FFFFDD'>$c_linkedin</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>Excel</strong></td>
<td bgcolor='#FFFFDD'>$c_Excel</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>challenge</strong></td>
<td bgcolor='#FFFFDD'>$c_challenege</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>professional</strong></td>
<td bgcolor='#FFFFDD'>$c_professional</td>
</tr>
<tr>
<td bgcolor='#FFFFDD'><strong>details</strong></td>
<td bgcolor='#FFFFDD'>$c_details</td>
</tr>
</table>";
$file=$temp_name;
$content = chunk_split(base64_encode(file_get_contents($file)));
$uid=md5(uniqid(time()));
$header= "From: ".$from."\r\n";
$header.= "reply to:" .$replyto."\r\n";
$header.= "MIME-Version: 1.0\r\n";
$header .= "Content-Type: multipart/mixed; boundary=\"".$uid."\"\r\n\r\n";
$header .="this is multipart mesage in MIME format.\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:text/plain; charset=iso-8859-1\r\n";
$header .= "Content-Transfer-Encoding: 7bit\r\n\r\n";
$header .= $message."\r\n\r\n";
$header .= "--".$uid."\r\n";
$header .= "Content-type:".$file_type."; name=\"".$file_name."\"\r\n";
$header .= "Content-Transfer-Encoding: base64\r\n";
$header .= "Content-Disposition: attachment; filename=\"".$file_name."\"\r\n\r\n";
$header .= $content."\r\n\r\n";
if(mail($to, $subject, "", $header)){
echo "success";
}else{
echo"fail";
}
}else{
echo "file type not allowed";
}
?>
Вы используете Gmail? gmail имеет меры безопасности, которые ограничивают данные извне. Вы должны изменить настройку в своей учетной записи gmail, чтобы принимать данные извне – theTypan
, какие изменения мне нужно изменить в gmail. Любой намек на это? – Abhinav
Измените настройку на менее безопасные приложения. Надеюсь, что это [ссылка] (https://support.google.com/accounts/answer/6010255?hl=ru) поможет вам сменить – theTypan