表格在特定邮政编码后不发送电子邮件

时间:2016-10-28 21:51:58

标签: php wordpress forms google-maps

晚上好,

这是一个奇怪的事情发生在这里。 我在automaker.nl上有一个表格,它会询问汽车赔偿的报价。除了某些zipcodes之外,它适用于所有人。

如果表单填写错误,则会出现错误,表示错误。但是对于这个邮政编码页面只是刷新并给我发送电子邮件不发送'消息。

好的,如果您去automaker.nl并填写荷兰牌照,例如SL-SL-81,那么请选择一个主题进行赔偿。 由于填写了车牌,下一页将自动填写车辆详细信息。 这里出现了奇怪的问题。 如果您填写所有信息(荷兰信息)并填写邮政编码(邮政编码)为9074EB,则不会出现任何问题并且已发送电子邮件。现在如果我填写完全相同的信息,除了邮政编码现在6524MS它给我这个消息没有错误。只是不发送任何东西。

邮政编码的代码是:

require_once ('classes/GoogleMapsApi.php');
require_once ('classes/Distance.php');
$distance = new Distance();
if ($_SERVER['REQUEST_METHOD'] == "POST" && isset($_POST['submit_reparation'])) {
$_POST['Image1'] = '';

if(!empty($_FILES['Image1'])) {
    $upload = new Upload();
    $upload->setDestination(__DIR__ . '/uploads');
    $upload->setFilename($_FILES['Image1']['name']);
    $upload->setPromission(644);
    $_POST['Image1'] = $upload->saveImage($_FILES['Image1']['tmp_name']);
}

if(empty($_POST['Title'])) {
    $error[] = "U heeft geen titel ingevuld";
}
if(empty($_POST['Merk'])) {
    $error[] = "U heeft geen auto merk geselecteerd";
}
if(empty($_POST['Handelsbenaming'])) {
    $error[] = "U heeft geen model geselecteerd";
}
if(empty($_POST['open_rdw-921'])) {
    $error[] = "U heeft geen kenteken ingevuld";
}
if(empty($_POST['Name'])) {
    $error[] = "U heeft geen naam ingevuld";
}
if(empty($_POST['Email'])) {
    $error[] = "U heeft geen e-mailadres ingevuld";
}
if(!filter_var($_POST['Email'], FILTER_VALIDATE_EMAIL)) {
    $error[] = "U heeft geen correct e-mailadres ingevuld";
}

if(empty($_POST['Zipcode'])) {
    $error[] = "U heeft geen postcode ingevuld";
}
elseif(empty($_POST['latitude'])) {
    $error[] = "U heeft geen correcte postcode ingevuld";
}
elseif(empty($_POST['longitude'])) {
    $error[] = "U heeft geen correcte postcode ingevuld";
}
elseif(!preg_match('/^[1-9][0-9]{3}\s?([a-zA-Z]{2})?$/', $_POST['Zipcode'])){
    $error[] = "U heeft geen correcte postcode ingevuld";
}

if (count($error) <= 0) {
    $pass = wp_generate_password ( 12, false );
    $register = array(
        'Title'            =>   $_POST['Title'],
        'Zipcode'            => $_POST['Zipcode'],
        'Description'        => $_POST['Description'],
        'Merk'             =>   $_POST['Merk'],
        'Handelsbenaming'    => $_POST['Handelsbenaming'],
        'LicensePlate'     =>   $_POST['open_rdw-921'],
        'Name'             =>   $_POST['Name'],
        'Phone'            =>   $_POST['Phone'],
        'Email'            =>   $_POST['Email'],
        'Latitude'         =>   $_POST['latitude'],
        'Longitude'        =>   $_POST['longitude'],
              'City'                 => $_POST['City'],
        'Image1'             => $_POST['Image1'],
        'Hash'             => md5(time()),
    );

    $wpdb->insert('Reparation', $register);

    if ($wpdb->insert_id) {
        $message = file_get_contents(__DIR__ . '/templates/reparation.html');
        $message = str_replace('%TITLE%', $_POST['Title'], $message);
        $message = str_replace('%DESCRIPTION%', $_POST['Description'], $message);
        $message = str_replace('%BRAND%', $_POST['Merk'], $message);
        $message = str_replace('%MODEL%', $_POST['Handelsbenaming'], $message);
        $message = str_replace('%LICENSEPLATE%', $_POST['open_rdw-921'], $message);
        $message = str_replace('%NAME%', $_POST['Name'], $message);
        $message = str_replace('%EMAIL%', $_POST['Email'], $message);
        $message = str_replace('%PHONE%', $_POST['Phone'], $message);
        $headers = array('Content-Type: text/html; charset=UTF-8','From: Automaker.nl <info@automaker.nl>' . "\r\n");
        wp_mail($_POST['Email'], 'Uw reparatie op Automaker.nl is succesvol verzonden', $message, $headers);

        $success = "Bedankt! Uw aanvraag is succesvol verstuurd. U zult snel offertes ontvangen.";

        $user_query = new WP_User_Query( array( 'role' => 'aamrole_5404aaeed25c7' ) );
              $Allbrands = $wpdb->get_results("SELECT allemerken FROM wp_users", OBJECT);
        $emails = array();
        if ( ! empty( $user_query->results ) ) {
            foreach ($user_query->results as $user) {
                $user_account_type = get_user_meta( $user->ID, 'account_type', true );

                $emails[] = $user->user_email;
                $point1 = array('lat' => $_POST['latitude'], 'long' => $_POST['longitude']);
                $point2 = array('lat' => $user->latitude, 'long' => $user->longitude);
                $retvalDistance = $distance->getDistance($point1['lat'], $point1['long'], $point2['lat'], $point2['long']);
                if($user_account_type != 3){
                  if ($retvalDistance <= $automaker['application']['distance'] && $Allbrands[0]->allemerken == 1) {
                      $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                      $message = str_replace('%TITLE%', $_POST['Title'], $message);
                      $message = str_replace('%GARAGE%', $user->company_name, $message);
                      $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                      if(!wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers)){
                        die("mail did not send");
                      }
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk1 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk2 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk3 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk4 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk5 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk6 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk7 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk8 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk9 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                  }
                            elseif ($retvalDistance <= $automaker['application']['distance'] && $user->Merk10 == $_POST['Merk']) {
                                $message = file_get_contents(__DIR__ . '/templates/reparation_garage.html');
                                $message = str_replace('%TITLE%', $_POST['Title'], $message);
                                $message = str_replace('%GARAGE%', $user->company_name, $message);
                                $headers = 'From: Automaker.nl <info@automaker.nl>' . "\r\n";
                                wp_mail($user->user_email, 'Er is een nieuwe reparatie geplaatst op Automaker.nl!', $message, $headers);
                }
              }
            }
        }
    }
}

}

Distance.php如下:

class Distance {

public function getDistance($lat1, $lon1, $lat2, $lon2)
{

    $pi80 = M_PI / 180;
    $lat1 *= $pi80;
    $lon1 *= $pi80;
    $lat2 *= $pi80;
    $lon2 *= $pi80;

    $r = 6372.797; // mean radius of Earth in km
    $dlat = $lat2 - $lat1;
    $dlon = $lon2 - $lon1;
    $a = sin($dlat / 2) * sin($dlat / 2) + cos($lat1) * cos($lat2) * sin($dlon / 2) * sin($dlon / 2);
    $c = 2 * atan2(sqrt($a), sqrt(1 - $a));
    $km = $r * $c;

    return $km;
}}

GoogleMapsAPi.php如下:

class GoogleMapsApi
{
    const MAPS_HOST = 'maps.google.com';

    protected $_latitude;
    protected $_longitude;
    protected $_address;
    protected $_countryName;
    protected $_countryNameCode;
    protected $_administrativeAreaName;
    protected $_postalCode;
    protected $_key;
    protected $_baseUrl;

    public function __construct ()
    {

    }

    /**
     * @param string $address
     *
     * @return bool
     */
    public function getInfoLocation ($address) {
        if (!empty($address)) {
            return $this->execute($address);
        }
        return false;
    }
    /**
     * connect to Google Maps
     *
     * @param string $param
     * @return boolean
     */
    private function execute($param) {
        $cityclean = str_replace (" ", "+", $param);
        $details_url = "http://maps.googleapis.com/maps/api/geocode/json?address=" . $cityclean . "&components=country:Nederland&sensor=false";

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_URL, $details_url);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        $geoloc = json_decode(curl_exec($ch), true);

        return $geoloc;
    }
}

感谢您的帮助,希望有人知道解决方案。

0 个答案:

没有答案