大家下午好,
我目前正在开发一个带距离计算的电子邮件系统,但它只能工作一半。电子邮件正在发送(它也在计算距离,只发送电子邮件,如果相同或低于100公里)。
但是电子邮件只发送一次,只有第一个MySQL行显示在我的电子邮件中。我不能收到我公司数据库中每家公司的电子邮件,而不仅仅是第一份公司的电子邮件吗? 目前我将自己的电子邮件设置为$ to变量,在收到所有电子邮件之后,我希望$ to成为所有其他公司的变量,作为一段时间的设置。
这是我的代码,希望有人可以帮助我。
add_action('gform_after_submission_1', 'send_to_kitchen_companies', 10, 2);
function send_to_kitchen_companies($entry, $form) {
$servername7 = 'localhost';
$username7 = 'username';
$password7 = 'password';
$dbname7 = 'databasename';
$conn7 = mysql_connect($servername7, $username7, $password7);
mysql_select_db('databasename');
$sqlAZ = 'SELECT * FROM creat_companies_zip_lat_long';
$resultpieAZ = mysql_query ($sqlAZ);
while($blsrowAZ = mysql_fetch_array($resultpieAZ, MYSQL_ASSOC)) {
function strafter($string, $substring) {
$pos = strpos($string, $substring);
if ($pos === false)
return $string;
else
return(substr($string, $pos+strlen($substring)));
}
function strbefore($string, $substring) {
$pos = strpos($string, $substring);
if ($pos === false)
return $string;
else
return(substr($string, 0, $pos));
}
$mylatlong = $entry['94'];
$mylat0 = strafter($mylatlong,'"');
$mylat1 = strafter($mylat0,'"');
$mylat2 = strafter($mylat1,'"');
$latitude1 = strbefore($mylat2,'"');
$mylong0 = strafter($mylat2,'"');
$mylong1 = strafter($mylong0,'"');
$mylong2 = strafter($mylong1,'"');
$mylong3 = strafter($mylong2,'"');
$longitude1 = strbefore($mylong3,'"');
$latitudecomp = $blsrowAZ['latitude'];
$longitudecomp = $blsrowAZ['longitude'];
$latitudeFrom = $latitude1;
$longitudeFrom = $longitude1;
$latitudeTo = $latitudecomp;
$longitudeTo = $longitudeFrom;
//Calculate distance from latitude and longitude
$theta = $longitudeFrom - $longitudeTo;
$dist = sin(deg2rad($latitudeFrom)) * sin(deg2rad($latitudeTo)) + cos(deg2rad($latitudeFrom)) * cos(deg2rad($latitudeTo)) * cos(deg2rad($theta));
$dist = acos($dist);
$dist = rad2deg($dist);
$miles = $dist * 60 * 1.1515;
$distance = ($miles * 1.609344);
if ($distance <= 100) {
$to = "myemail@email.com";
$subject = "Een test email in HTML";
$message = "
<html>
<head>
<title>Test HTML email</title>
</head>
<body>
<p>Geachte " . $blsrowAZ['field_company_name_value'] . " De afstand is minder dan 100 kilometer en dus geschikt voor email</p>
<table>
<tr>
<th>Latitude Aanvrager</th>
<th>Longitude Aanvrager</th>
</tr>
<tr>
<td>". $latitude1 ."</td>
<td>". $longitude1 ."</td>
</tr>
<tr>
<td>Latitude Bedrijf</td>
<td>Longitude Bedrijf</td>
</tr>
<tr>
<td>". $latitudecomp ."</td>
<td>". $longitudecomp ."</td>
</tr>
<tr>
<td>Totale Afstand</td>
</tr>
<tr>
<td>". $distance ."</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n".
"Content-type:text/html;charset=UTF-8" . "\r\n".
'From: info@keukenaanbod.nl' . "\r\n".
'Reply-To: no-reply@keukenaanbod.nl' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to,$subject,$message,$headers);
}
}
}
mysql_close($conn7);
答案 0 :(得分:1)
你的MAIN问题是你在循环中声明函数,第二次尝试声明函数时会抛出函数已经存在的错误。在循环外移动函数声明