我正在尝试与PHP建立联系表单。这个代码不能运作,还是我在监督什么?它有点基础,但我只是想让它先工作。
mLocationRequest = LocationRequest.create();
mLocationRequest.setPriority(LocationRequest.PRIORITY_HIGH_ACCURACY);
mLocationRequest.setInterval(1000); // Update location every second
if (ContextCompat.checkSelfPermission(this, android.Manifest.permission.ACCESS_FINE_LOCATION)
== PackageManager.PERMISSION_GRANTED) {
LocationServices.FusedLocationApi.requestLocationUpdates(mGoogleApiClient, mLocationRequest, this);
mMap.setMyLocationEnabled( true );
mLastLocation = LocationServices.FusedLocationApi.getLastLocation(
mGoogleApiClient);
if (mLastLocation != null) {
lat = String.valueOf(mLastLocation.getLatitude());
lon = String.valueOf(mLastLocation.getLongitude());
}
firstLoction();
}
else
{
Toast.makeText(this, "Not promisseion", Toast.LENGTH_SHORT).show();
}
答案 0 :(得分:2)
更改此
<input type="submit" value="Submit" name="submit"> # add name field
在您的邮件代码中
if (isset($_POST['submit'])) {
$to = 'xxxx@gmail.com';
$subject = 'This came from the other world';
$name = $_POST['name'];
$email = $_POST['email'];
$msg = $_POST['message'];
$message = "Customer Name : ".$name\r\n;
$message .= "Customer Email : ".$email\r\n;
$message .= "Customer Message : ".$msg\r\n;
$headers = "MIME-Version: 1.0\r\n";
$headers .= "Content-Type: text/html; charset=ISO-8859-1\r\n";
if (!mail($to, $subject, $message, $headers)) {
echo "Sending Failed";
}
else{
echo "Your Message has been send";
}
}
如果您在localhost中发送邮件,请查看此
答案 1 :(得分:1)
您的标题需要包含实际的电子邮件标题,您只需重复电子邮件地址。
示例:
$to = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: webmaster@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($to, $subject, $message, $headers);
documentation on the mail()
function会告诉您标题和换行符的重要性,并为您提供安全提示。
答案 2 :(得分:1)
尝试阅读此http://php.net/manual/de/function.mail.php
我认为你的问题是这个代码行
$header = '$email';
您的标题将是字符串$ email,而不是$ email var
的值