Письма о приеме на работу не всегда принимаются (PHP) - PullRequest
0 голосов
/ 31 мая 2018

Я отвечаю за форму заявления о приеме на работу, которая, кажется, не работает должным образом.Проблема в том, что письма из этой формы не всегда получают.Странный факт заключается в том, что я также настроил адрес электронной почты CC в этом сценарии (другой сервер), и этот адрес электронной почты всегда получает почту в этой папке входящих сообщений.Лично я считаю, что это проблема с сервером, но, возможно, я что-то упустил.

ОБНОВЛЕНИЕ: на этом же сервере запущен другой веб-сайт с контактной формой, которая работает нормально.

См. Мойкод ниже.

Любая помощь будет принята с благодарностью.

<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!DOCTYPE html>
<html lang="nl">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>title</title>
  <meta name="description" content="" />
  <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
  <link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.0.9/css/all.css" integrity="sha384-5SOiIsAziJl6AWe0HWRKTXlfcSHKmYV4RBF18PPJ173Kzn7jzMyFuTtk8JA7QQG1" crossorigin="anonymous">
  <link rel="stylesheet" href="style.css" crossorigin="anonymous">
  <!--[if IE 9]><link rel="stylesheet" href="ie.css" type="text/css" /><![endif]-->
  <!--[if IE 8]><link rel="stylesheet" href="ie.css" type="text/css" /><![endif]-->
  <!--[if IE 7]><link rel="stylesheet" href="ie.css" type="text/css" /><![endif]-->
  <script src='https://www.google.com/recaptcha/api.js'></script>


</head>



<body>


  <div class="container">


    <div class="content">

      <div style="display:flex; align-items:flex-start; justify-content:flex-start!important; padding:20px 0px 20px 0px; height:100%; flex-wrap:wrap;" class="wrapper">

        <div class="block padding-left">

          <div class="padding-mobile" style="width:100%; height:auto; display:flex; align-items:flex-start; justify-content:flex-start; margin-top:60px; flex-wrap:wrap; box-sizing:border-box;">

            <h2 style="font-size:42px; margin:0px;">Apply</h2>

            <form enctype="multipart/form-data" id="cv" class="formulier" method="POST" action="">

              <p>
                <label>First name:</label>
                <input data-validation="required" type="text" name="naam" placeholder="Uw naam" />
              </p>

              <p>
                <label>Last name:</label>
                <input data-validation="required" type="text" name="achternaam" placeholder="Uw achternaam" />
              </p>

              <p>
                <label>Telephone</label>
                <input data-validation="required" type="text" name="telefoon" placeholder="Uw telefoonnummer" />
              </p>

              <p>
                <label>Email address</label>
                <input data-validation="required email" type="text" name="email" placeholder="Uw email adres" />
              </p>

              <p>
                <label>Select a job application</label>
                <select name="vacature" placeholder="Vacature" data-validation="length" data-validation-length="min1" data-validation-error-msg="Selecteer een vacature">
                  <option value="" disable selected>Vacature</option>
                  <option>- Open sollicitatie- </option>
                  <option>Administratief medewerker bedrijfskantoor (m/v)</option>
                  <option>Inkoper</option>
                  <option>Leerling Operators</option>
                  <option>Snijder (m/v)</option>
                  <option>Planner</option>
                  <option>Accountmanager Frankrijk</option>
                  <option>Offsetdrukker Vellen</option>
                  <option>Oproepkrachten</option>
                  <option>Weekend-/ vakantiewerkers</option>
                  <option>Assistent Machineoperator (m/v)</option>
                  <option>Offsetrotatiedrukkers Heatset (m/v)</option>
                  <option>Software developer</option>
                  <option>Allround onderhoudsmonteur</option>
                  <option>Magazijnmedewerker (m/v)</option>
                </select>

              </p>

              <p style="background:#fff; padding:20px; margin-top:44px; color:#000; border-radius:6px;">
                <label style="color:#555; text-shadow:none!important; font-size:18px;">Upload your CV</label>
                <input type="file" name="cv" data-validation="mime size" data-validation-allowing="pdf, docx, doc, docm, rtf" data-validation-max-size="2M" />
              </p>

              <p align="center">Please vrify that you are human.</p>

              <div class="g-recaptcha" data-sitekey="---sitekey----" style="margin-bottom:20px;" align="center"></div>

              <input type="submit" value="Verzend mijn sollicitatie!" />

            </form>

            <script>
              $("form#cv")
                .attr("enctype", "multipart/form-data")
                .attr("encoding", "multipart/form-data");
            </script>
            <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
            <script src="//cdnjs.cloudflare.com/ajax/libs/jquery-form-validator/2.3.26/jquery.form-validator.min.js"></script>
            <script>
              $.validate({
                modules: 'file',
                lang: 'nl'
              });
            </script>



          </div>


        </div>

        <div class="block">

          <div class="circle" style="border-radius:600px; border:solid 10px #fff; margin-top:60px; background:url(wrapper.png); background-size:160% auto!important; background-position:-150px 0!important; box-sizing:border-box;"></div>

        </div>

        <div class="clear"></div>


        <div class="block padding-left inline-block">

          <div style="text-align:center; display:flex; align-items:center; justify-content:center; width:90%;">
            <?php 
					if(isset($_POST['email'])) {
					
					if(isset($_POST['g-recaptcha-response'])){
          $captcha=$_POST['g-recaptcha-response'];
        }
        if(!$captcha){
          echo '<div class="notific" style="background:rgba(192, 0, 0, 0.8); display:flex; align-items:center; justify-content:center; border-radius:6px; margin-top:20px; padding:0px 15px 0px 15px;"><i style="margin:0px 10px 0px 10px; color:#fff; font-size:32px; text-shadow: 1.2px 1.2px 1.2px #000;" class="fas fa-exclamation-triangle"></i><h2 style="font-size:28px!important;">Bevestig dat u een mens bent.</h2></div>';
		?>

            <script>
              $('html, body').animate({
                scrollTop: $("div.notific").offset().top
              }, 1000)
            </script>

            <?php
          exit;
        }
					
		$secretKey = "--secretkey--";
        $ip = $_SERVER['REMOTE_ADDR'];
        $response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
        $responseKeys = json_decode($response,true);
        if(intval($responseKeys["success"]) !== 1) {
          echo '<div class="notific" style="background:rgba(192, 0, 0, 0.8); display:flex; align-items:center; justify-content:center; border-radius:6px; margin-top:20px; padding:0px 15px 0px 15px;"><i style="margin:0px 10px 0px 10px; color:#fff; font-size:32px; text-shadow: 1.2px 1.2px 1.2px #000;" class="fas fa-exclamation-triangle"></i><h2 style="font-size:28px!important;">Er ging iets mis, probeer het nog eens.</h2></div>';
			
		?>

              <script>
                $('html, body').animate({
                  scrollTop: $("div.notific").offset().top
                }, 1000)
              </script>

              <?php
			
        } else {

          echo '<div class="notific" style="background:rgba(0, 226, 37, 0.8); display:flex; align-items:center; justify-content:center; border-radius:6px; margin-top:20px; padding:0px 15px 0px 15px;"><i style="margin:0px 10px 0px 10px; color:#fff; font-size:32px; text-shadow: 1.2px 1.2px 1.2px #000;" class="fas fa-check-square"></i><h2 style="font-size:28px!important;">Bedankt voor uw aanmelding.</h2></div>';
			
		?>

                <script>
                  $('html, body').animate({
                    scrollTop: $("div.notific").offset().top
                  }, 1000)
                </script>

                <?php
        }
						
					}
					
					?>
          </div>

        </div>

      </div>

    </div>


    <?php
	
	if(isset($_POST['email']) && isset($_FILES['cv'])) {	
	
		$naam = $_POST['naam'];
		$achternaam = $_POST['achternaam'];
		$telefoon = $_POST['telefoon'];
		$email = $_POST['email'];
		$vacature = $_POST['vacature'];
		
		
		
		$to = 'email@email.com';
		$from = 'email@email.com';

		$subject = 'Nieuwe sollicitatie op vacature';
	
	
		$message = "<p><b>Details sollicitatie:</b></p>
		
		<p>Naam: $naam </p>
		<p>Achternaam: $achternaam </p>
		<p>Telefoon: $telefoon </p>
		<p>Email: $email </p>
		<p>Vacature: $vacature</p>	
		</html>
		";
		
		
    	$file_tmp_name    = $_FILES['cv']['tmp_name'];
    	$file_name        = $_FILES['cv']['name'];
    	$file_size        = $_FILES['cv']['size'];
    	$file_type        = $_FILES['cv']['type'];
    	$file_error       = $_FILES['cv']['error'];
	
    	//read from the uploaded file & base64_encode content for the mail
    	$handle = fopen($file_tmp_name, "r");
    	$content = fread($handle, $file_size);
    	fclose($handle);
    	$encoded_content = chunk_split(base64_encode($content));
	

	  	$boundary = md5("em");
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from."\r\n"; 
        $headers .= "Reply-To: ".$to."" . "\r\n";
		$headers .= 'Cc: cc@email.com' . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 
	
		
        //plain text 
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($message)); 
        
		
        //attachment
        $body .= "--$boundary\r\n";
        $body .="Content-Type: $file_type; name=".$file_name."\r\n";
        $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
        $body .="Content-Transfer-Encoding: base64\r\n";
        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
        $body .= $encoded_content; 

		mail($to, $subject, $body, $headers, '-f email@email.com');
			
	} else {}
		
	if(isset($_POST['email']) && !isset($_FILES['cv'])) {	
	
		$naam = $_POST['naam'];
		$achternaam = $_POST['achternaam'];
		$telefoon = $_POST['telefoon'];
		$email = $_POST['email'];
		$vacature = $_POST['vacature'];
		
		$to = 'email@email.com';
		$from = 'email@email.com';

		$subject = 'Nieuwe sollicitatie op vacature';
	
	
		$message = "<p><b>Details sollicitatie:</b></p>
		
		<p>Naam: $naam </p>
		<p>Achternaam: $achternaam </p>
		<p>Telefoon: $telefoon </p>
		<p>Email: $email </p>
		<p>Vacature: $vacature</p>	
		</html>
		";
		
		
    	$file_tmp_name    = $_FILES['cv']['tmp_name'];
    	$file_name        = $_FILES['cv']['name'];
    	$file_size        = $_FILES['cv']['size'];
    	$file_type        = $_FILES['cv']['type'];
    	$file_error       = $_FILES['cv']['error'];
	
    	//read from the uploaded file & base64_encode content for the mail
    	$handle = fopen($file_tmp_name, "r");
    	$content = fread($handle, $file_size);
    	fclose($handle);
    	$encoded_content = chunk_split(base64_encode($content));
	

	  	$boundary = md5("sanwebe");
        //header
        $headers = "MIME-Version: 1.0\r\n"; 
        $headers .= "From:".$from."\r\n"; 
        $headers .= "Reply-To: ".$to."" . "\r\n";
		$headers .= 'Cc: cc@email.com' . "\r\n";
        $headers .= "Content-Type: multipart/mixed; boundary = $boundary\r\n\r\n"; 
	
		
        //plain text 
        $body = "--$boundary\r\n";
        $body .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
        $body .= "Content-Transfer-Encoding: base64\r\n\r\n"; 
        $body .= chunk_split(base64_encode($message)); 
        
		
        //attachment
        $body .= "--$boundary\r\n";
        $body .="Content-Type: $file_type; name=".$file_name."\r\n";
        $body .="Content-Disposition: attachment; filename=".$file_name."\r\n";
        $body .="Content-Transfer-Encoding: base64\r\n";
        $body .="X-Attachment-Id: ".rand(1000,99999)."\r\n\r\n"; 
        $body .= $encoded_content; 

		mail($to, $subject, $body, $headers, '-f email@email.com ');
			
	} else {}
	
	?>


</body>

</html>

1 Ответ

0 голосов
/ 31 мая 2018

По моему опыту, ситуация такого типа не связана с вашим кодом.Вы можете проверить свой phpmail.log, но я подозреваю, что вы увидите все свои электронные письма в списке.

Ключевым моментом здесь является то, что CC всегда получен.Это означает, что ваши письма отправляются, но не доставляются.Это указывает на вашу конфигурацию DNS.Это может быть ваша запись SPF или отсутствие записи в DKIM.

Поскольку вы используете функцию mail () PHP, вы не отправляете через аутентифицированный SMTP.Я бы рекомендовал @ CBroe использовать почтовую библиотеку, но по другой причине.Это предоставит вам возможность использования аутентифицированного SMTP, который будет иметь гораздо более высокую возможность доставки.

Я бы порекомендовал:

  • Проверьте запись SPF и убедитесь, что она включает IP-адрес вашего сервера.Предпочтительно это будет заканчиваться на «-all» (избегать «+ все»).
  • Использовать почтовую библиотеку PHP и использовать аутентифицированный SMTP.Это не является обязательным требованием, но делает кодирование электронной почты быстрее, проще и менее подвержено ошибкам.SMTP с проверкой подлинности никогда не снижает ваши шансы на доставку.
  • Если возможно, настройте запись DKIM для своего домена.
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...