Quantcast
Channel: Active questions tagged email - Stack Overflow
Viewing all articles
Browse latest Browse all 29748

Can I make Azure app send email with mail() function?

$
0
0

I have the code below which works for me on my test server, but not in "Azure App services" because it doesn't have its own "SMTP server".

Are there some simple way to make the code work or do I need to change it entirely?

I have SMTP server, which I can use, but I really don't know how.

I know practically nothing about php and azure servers.

<?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>'; 
    }
}

?>

Thanks for the help in advance.


Viewing all articles
Browse latest Browse all 29748

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>