2015-07-18 2 views
-2

Я использую этот код для своей формы PHP, где я добавил слишком много полей Я хочу получить эту форму в формате HTML, в то время как ее общее сообщение также в письме должно прилагаться к файлу .. который также не приходит это PHP обратно код этогоhtml mail получить php-форму

<?php 
/** CONFIGURATION OPTIONS 
* $email_address = The email address that all form submissions will be sent to 
* $company_address = The destination address that will be used in the contact form */ 
$email_address = '[email protected]'; 
$company_address = 'Delhi, India'; 
// 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"; 
/** DO NOT EDIT ANYTHING BELOW THIS LINE UNLESS YOU ARE COMFORTABLE WITH PHP */ 
echo "<script>var companyAddress = '".$company_address."';</script>"; 

$field_rules = array(
    'name' => 'required', 
    'email' => 'required|valid_email', 
    'phone' => '', 
    'contact_reason' => 'required', 
    'message' => 'required' 
); 


$error_messages = array(
    'required' => 'This field is required', 
    'valid_email' => 'Please enter a valid email address' 
); 


$error_list = ''; 


$fields = $_POST; 



if (!empty($fields)) 
{ 
    //Validate each of the fields 
foreach ($field_rules as $field => $rules) 
{ 
    $rules = explode('|', $rules); 

    foreach ($rules as $rule) 
    { 
     $result = null; 

     if (isset($fields[$field])) 
     { 
      if (!empty($rule)) 
       $result = $rule($fields[$field]); 

      if ($result === false) 
      { 
       $field_name = ucwords(implode(' ', explode('_', $field))); 

       $error_list .= "<div class='error'>$field_name: " . $error_messages[$rule] . "</div>"; 
      } 
     } 
    } 
} 

if (empty($error_list)) 
{ 
    $subject = '[Application for Employment] New message from ' . $fields['name'] . '.'; 
    $content = $fields['name'] . " sent you a message from your contact form:\r\n\n"; 
    $content .= "-------\n" . $fields['message'] . "\r\n\n"; 
    $content .= "Position Applied For: " . $fields['positionapplied'] 
      . " \n\nTelephone Number: " . $fields['telephonenumber'] 
      . " \n\nMobile Number: " . $fields['mobilenumber'] 
      . " \n\nEmail: " . $fields['email'] 
      . " \n\nDate of Birth: " . $fields['bday'] 
      . " \n\nGender: " . $fields['gender'] 
      . " \n\nPermanent Address: " . $fields['permanentaddress'] 
      . " \n\nCity: " . $fields['city'] 
      . " \n\nState: " . $fields['state'] 
      . " \n\nPin: " . $fields['pin'] 
      . " \n\nMarital Status: " . $fields['marital_status'] 
      . " \n\nFather Name: " . $fields['fathername'] 
      . " \n\nFather Occupation: " . $fields['fatheroccupation'] 
      . " \n\nMother Name: " . $fields['mothername'] 
      . " \n\nMother Age: " . $fields['motherage'] 
      . " \n\nMother Occupation: " . $fields['motheroccupation'] 
      . " \n\nSpouse Name: " . $fields['spousename'] 
      . " \n\nSpouse Age: " . $fields['spouseage'] 
      . " \n\nSpouse Occupation: " . $fields['spouseoccupation'] 
      . " \n\nBrother Name: " . $fields['brothername'] 
      . " \n\nBrother Age: " . $fields['brotherage'] 
      . " \n\nBrother Occupation: " . $fields['brotheroccupation'] 
      . " \n\nSister Name: " . $fields['sistername'] 
      . " \n\nSister Age: " . $fields['sisterage'] 
      . " \n\nSister Occupation: " . $fields['sisteroccupation'] 
      . " \n\nEducation Qualification Course1: " . $fields['educationqualificationcourse1'] 
      . " \n\nEducation Qualification University1: " . $fields['educationqualificationuniversity1'] 
      . " \n\nName of the College or School: " . $fields['nameofschool1'] 
      . " \n\nEducation Qualification Year From 1: " . $fields['educationqualificationyearfrom1'] 
      . " \n\nEducation Qualification Year to 1: " . $fields['educationqualificationyearto1'] 
      . " \n\nEducation Qualification Percentage 1: " . $fields['educationqualificationclasspercentage1'] 
      . " \n\nEducation Qualification Specialisation1: " . $fields['educationqualificationspecialisation1'] 
      . " \n\nEducation Qualification Course2: " . $fields['educationqualificationcourse2'] 
      . " \n\nEducation Qualification University2: " . $fields['educationqualificationuniversity2'] 
      . " \n\nName of School2: " . $fields['nameofschool2'] 
      . " \n\nEducation Qualification Year from 2: " . $fields['educationqualificationyearfrom2'] 
      . " \n\nEducation Qualification Year to 2: " . $fields['educationqualificationyearto2'] 
      . " \n\nEducation Qualification Class Percentage 2: " . $fields['educationqualificationclasspercentage2'] 
      . " \n\nEducation Qualification Course3: " . $fields['educationqualificationspecialisation2'] 
      . " \n\nEducation Qualification Specialisation 2: " . $fields['educationqualificationspecialisation2'] 
      . " \n\nEducation Qualification Course 3: " . $fields['educationqualificationcourse3'] 
      . " \n\nEducation Qualification University 3: " . $fields['educationqualificationuniversity3'] 
      . " \n\nName of School 3: " . $fields['nameofschool3'] 
      . " \n\nEducation Qualification Year from 3: " . $fields['educationqualificationyearfrom3'] 
      . " \n\nEducation Qualification Year To 3: " . $fields['educationqualificationyearto3'] 
      . " \n\nEducation Qualification class Percentage 3: " . $fields['educationqualificationclasspercentage3'] 
      . " \n\nEducation Qualification Epecialisation 3: " . $fields['educationqualificationspecialisation3'] 
      . " \n\nComputer Proficiency Package Language: " . $fields['computerproficiencypackagelanguage'] 
      . " \n\nComputer Proficiency Excellent: " . $fields['computerproficiencyexcellent'] 
      . " \n\nComputer Proficiency Good: " . $fields['computerproficiencygood'] 
      . " \n\nComputer Proficiency Average: " . $fields['computerproficiencyaverage'] 
      . " \n\nProfessional Courses Programe 1: " . $fields['professionalcoursesprograme1'] 
      . " \n\nProfessional Courses Duration 1: " . $fields['professionalcoursesduration1'] 
      . " \n\nProfessional Courses year 1: " . $fields['professionalcoursesyear1'] 
      . " \n\nProfessional Courses Organised by 1: " . $fields['professionalcoursesorganisedby1'] 
      . " \n\nProfessional Courses Programe 2: " . $fields['professionalcoursesprograme2'] 
      . " \n\nProfessional Courses Duration 2: " . $fields['professionalcoursesduration2'] 
      . " \n\nProfessional Courses Year 2: " . $fields['professionalcoursesyear2'] 
      . " \n\nProfessional Courses Organised by 2: " . $fields['professionalcoursesorganisedby2'] 
      . " \n\n Employment Experience Name Address Organisation 1: " . $fields['employmentexpnameaddressorganisation1'] 
      . " \n\nEmployment Exp Name Year From 1: " . $fields['employmentexpnameyearfrom1'] 
      . " \n\nEmployment Exp Name Year to 1: " . $fields['employmentexpnameyearto1'] 
      . " \n\nEmployment Exp Position 1: " . $fields['employmentexpposition1'] 
      . " \n\nEmployment Exp Location 1: " . $fields['employmentexplocation1'] 
      . " \n\nEmployment Exp Reason Leaving 1: " . $fields['employmentexpreasonleaving1'] 
      . " \n\nEmployment Exp Name Address Organisation 2: " . $fields['employmentexpnameaddressorganisation2'] 
      . " \n\nEmployment Exp Name Year From 2: " . $fields['employmentexpnameyearfrom2'] 
      . " \n\nEmployment Exp Name Year To 2: " . $fields['employmentexpnameyearto2'] 
      . " \n\nEmployment Exp Position 2: " . $fields['employmentexpposition2'] 
      . " \n\nEmployment Exp Location 2: " . $fields['employmentexplocation2'] 
      . " \n\nEmployment Exp Reason Leaving 2: " . $fields['employmentexpreasonleaving2'] 
      . " \n\nEmployment Exp Name Address Organisation 3: " . $fields['employmentexpnameaddressorganisation3'] 
      . " \n\nEmployment Exp Name Year From 3: " . $fields['employmentexpnameyearfrom3'] 
      . " \n\nEmployment Exp Name Year To 3: " . $fields['employmentexpnameyearto3'] 
      . " \n\nEmployment Exp Position 3: " . $fields['employmentexpposition3'] 
      . " \n\nEmployment Exp Location 3: " . $fields['employmentexplocation3'] 
      . " \n\nEmployment Exp Reason Leaving 3: " . $fields['employmentexpreasonleaving3'] 
      . " \n\nCurrent Last Salary: " . $fields['currentlastsalary'] 
      . " \n\nReferences Name 1: " . $fields['referencesname1'] 
      . " \n\nReferences Designation 1: " . $fields['referencesdesignation1'] 
      . " \n\nReferences Company Name 1: " . $fields['referencescompanyname1'] 
      . " \n\nReferences Contact No 1: " . $fields['referencescontactno1'] 
      . " \n\nReferences Email Id 1: " . $fields['referencesemailid1'] 
      . " \n\nReferences Name 2: " . $fields['referencesname2'] 
      . " \n\nReferences Designation 2: " . $fields['referencesdesignation2'] 
      . " \n\nReferences Company Name 2: " . $fields['referencescompanyname2'] 
      . " \n\nReferences Contact No 2: " . $fields['referencescontactno2'] 
      . " \n\nReferences Email Id 2: " . $fields['referencesemailid2'] 
      . " \n\nReferences Name 1: " . $fields['referencesname1'] 
      . " \n\nFile: " . $fields['uploadField'] 
      . " \n\nSubmission Date: " . $fields['submissiondate'] . " \n\n"; 



    if (mail($email_address, $subject, $content, "From: " . $fields['email'] . "\r\nReply-To: " . $fields['email'] . "\r\nReturn-Path: " . $fields['email'] . "\r\n")) 
    { 

     echo "<h2 class='success'>Message Sent</h2>"; 
     echo "<br/><p class='success'>Thank you <strong>" . $fields['name'] . "</strong>, your message has been submitted and someone will contact you shortly.</p>"; 
    } 
    else 
    { 

     echo 'ERROR!'; 
    } 
} 

}

функции требуется ($ ул, $ = Val ложь) {

if (!is_array($str)) 
{ 
    $str = trim($str); 
    return ($str == '') ? false : true; 
} 
else 
{ 
    return (!empty($str)); 
} 

}

function valid_email($str) 
    { 
    return (!preg_match("/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}@)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*@(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/iD", $str)) ? false : true; 
} 

ответ

0

Написание кода для отправки почты с PHP является основной головной болью, поверьте мне, я потратил часы, пытаясь сделать это вручную. Вы, наконец, заработаете, а затем, о, Google считает, что это спам. Тогда другая служба считает, что это спам. Не стоит вашего времени. Поэтому я настоятельно рекомендую использовать такую ​​услугу, как http://www.mailgun.com/, которая предлагает 10 000 электронных писем в месяц бесплатно. Ознакомьтесь с этим руководством, чтобы начать: http://blog.mailgun.com/php-how-to-use-mailgun-efficiently/. Поверьте мне, вы хотите это сделать.

+0

Hello Thestepafter ... спасибо за ранний ответ. но в настоящее время я не могу пойти на другие .. Пожалуйста, дайте мне решение для этого –

+0

http://synergywebdesigners.com/safe/ это URL-адрес, где я обновил Front end .. Я также не получаю аттестационный файл, пожалуйста, дайте мне решение. –

+0

Я не уверен, почему вы не можете использовать mailgun, это бесплатно использовать, и форма, как вы только что показали мне, скорее всего, не получит 10 000 представлений в месяц. С учетом сказанного, если вы настаиваете на отправке почты вручную без стороннего сервиса, я рекомендую использовать пакет PHP, например https://packagist.org/packages/nette/mail. – thestepafter