2017-09-02 128 views
0

我寫過用PHP發送郵件腳本。當我按下發送按鈕腳本加載這麼久。 Finnaly它不加載。當我刪除的ReCaptcha檢查,頁面加載這麼快,給我一個錯誤500 代碼:爲什麼腳本加載速度太慢[PHP]

<?php 
session_start(); 
$curl = curl_init(); 
curl_setopt_array($curl, [ 
    CURLOPT_RETURNTRANSFER => 1, 
    CURLOPT_URL => 'https://www.google.com/recaptcha/api/siteverify', 
    CURLOPT_PORT => 1, 
    CURLOPT_POSTFIELDS => [ 
     'secret' => '_____SECRET!____', 
     'response' => $_POST['g-recaptcha-response'], 
    ], 
]); 
$response = curl_exec($curl); 
if(!$response->success){ 
    $_SESSION['success'] = false; 
    $_SESSION['message'] = 'Nie zaznaczono pola: "Nie jestem robotem".'; 
    $_SESSION['redirect'] = $_SERVER['HTTP_REFERER']; 
    header("result.php"); 
}else{ 
    $name = $_POST['name']; 
    $email = $_POST['email']; 
    $content = $_POST['content']; 
    if(isset($name) && isset($email) && isset($content)){ 
     $content = n12br($content); 
     $to = "[email protected]"; 
     $from = $email; 
     $subject = 'Terapiaautyzmu.pl - Email'; 
     $message = '<b>Imie i nazwisko:</b> '.$name.' <br><b>Email:</b> '.$from.' <p>'.$content.'</p>'; 
     $headers = "From: $from\n"; 
     $headers .= "MIME-Version: 1.0\n"; 
     $headers .= "Content-type: text/html; charset=utf-8\n"; 
     $result = mail($to, $subject, $message, $headers); 
     if($result){ 
      $_SESSION['success'] = true; 
      $_SESSION['message'] = 'Wysłano emaila.'; 
      $_SESSION['redirect'] = $_SERVER['HTTP_REFERER']; 
      header("result.php"); 
     }else { 
      $_SESSION['success'] = false; 
      $_SESSION['message'] = 'Serwer odrzucił wysłanie emaila". Sprawdź czy wszystkie pola zostały wypełnione poprawnie.'; 
      $_SESSION['redirect'] = $_SERVER['HTTP_REFERER']; 
      header("result.php"); 
     } 
    } 
} 

>

+0

試着找出哪部分代碼實際上很慢。你可以通過評論郵件部分或捲曲部分來做到這一點,並看看哪部分實際上佔用了太多時間。 – Ivar

回答

0

您可能要發送郵件的background task through a queue

在某些情況下,您會從等待直接從電子郵件2.60秒到queue-exec-background 0.024秒,這是對x11的改進更快。

相關問題