我可以使Azure应用程序通过mail()函数发送电子邮件吗?

时间:2020-01-14 11:49:47

标签: php azure email azure-web-app-service azure-webapps

下面有我可以在我的测试服务器上使用的代码,但在“ Azure App服务”中却没有,因为它没有自己的“ SMTP服务器”。

是否有一些简单的方法可以使代码正常工作,或者我需要完全更改它?

我有可以使用的SMTP服务器,但我真的不知道如何使用。

我对php和azure服务器几乎一无所知。

<?php

    mb_internal_encoding("UTF-8");
    //index.php

    $error = '';
    $name = '';
    $email = '';
    $surname = '';
    $phone = '';
    $secretKey = 'Hehe';
    $captcha = $_POST['g-recaptcha-response'];

   function clean_text($string)
   {
       $string = trim($string);
       $string = stripslashes($string);
       $string = htmlspecialchars($string);

       return $string;
    }

   if(isset($_POST["submit"]))
   {
       if(empty($_POST["name"]))
       {
           $error .= '<p><label class="text-danger">Vložte své jméno prosím.
</label></p>';
       }
       else
       {
           $name = clean_text($_POST["name"]);
       }
       if(empty($_POST["email"]))
       {
            $error .= '<p><label class="text-danger">Zadejte svůj email prosím.</label></p>';
       }
       else
       {
           $email = clean_text($_POST["email"]);
           if(!filter_var($email, FILTER_VALIDATE_EMAIL))
           {
               $error .= '<p><label class="text-danger">Nesprávný formát emailu.</label></p>';
           }
       }
       if(empty($_POST["surname"]))
       {
           $error .= '<p><label class="text-danger">Zadejte prosím své 
 příjmení.</label></p>';
       }
       else
       {
           $surname = clean_text($_POST["surname"]);
       }
       if(empty($_POST["phone"]))
       {
           $error .= '<p><label class="text-danger">Zadejte prosím své 
telefonní číslo.</label></p>';
       }
       else
       {
           $phone = clean_text($_POST["phone"]);
       }


$response=file_get_contents("https://www.google.com/recaptcha/api/siteverify?secret=".$secretKey."&response=".$captcha."&remoteip=".$ip);
 $responseKeys = json_decode($response,true);

      if($error == '' && intval($responseKeys["success"]) == 1)
      {
          $file_open = fopen("pxJTVuaPrxbo4KJKawLI/contact_data.csv", "a");
          $no_rows = count(file("pxJTVuaPrxbo4KJKawLI/contact_data.csv"));
          if($no_rows > 1)
          {
              $no_rows = ($no_rows - 1) + 1;
          }
          $form_data = array(
              'sr_no'  => $no_rows,
              'name' => $name,
              'surname' => $surname,
              'email'  => $email,
              'phone' => $phone
          );

          $recipients = array(
              "info@optimal-energy.cz",
              "matej.konecny@getmore.cz",
          );
         $EmailTo = implode(',', $recipients); // your email address
         $EmailFrom = $email;
         $Subject = "Kariérní stránka OE - Nový zájemce o pozici";

         $headers .= "Reply-To: ". strip_tags($_POST['email']) . "\r\n";
         $headers .= "From: info@getmore.cz\r\n";
         $headers .= "MIME-Version: 1.0\r\n";
         $headers .= "Content-Type: text/html; charset=UTF-8\r\n";

         $message = '<html><body>';
         $message .= '<p style="color:#080;font-size:18px;">Z kariérního webu Optimal Energy přišel nový kontakt!</p>';
         $message .= '<b>Jméno:</b>&nbsp;&nbsp;&nbsp;&nbsp;'.$name;
         $message .= '<br><b>Příjmení:</b>&nbsp;&nbsp;&nbsp;&nbsp;'.$surname;
         $message .= '<br><b>Email:</b>&nbsp;&nbsp;&nbsp;&nbsp;'.$email;
         $message .= '<br><b>Telefonní číslo: </b>&nbsp;&nbsp;&nbsp;&nbsp;'.$phone;
  $message .= '</body></html>';

         mail($EmailTo, $Subject, $message, $headers);

        fputcsv($file_open, $form_data);
        fclose($file_open);
        $error = '<div class="text-center"><label class="text-success">Děkujeme za Váš zájem. V blízké době Vás budeme kontaktovat.</label><div>';
        $name = '';
        $surname = '';  
        $email = '';
        $phone = '';
    }
    else
    {
        $error .= '<p><label class="text-danger">Opravdu nejste robot?</label></p>'; 
    }
}

?>

非常感谢您的帮助。

0 个答案:

没有答案
相关问题