在 php 邮件上获取 302($to Email, $email Subject, $body, $headers);
Getting 302 on a php mail($toEmail, $emailSubject, $body, $headers);
我有一个托管实例,仅用于测试上面的 2 个文件
index.html 和 contact.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple contact Form</title>
</head>
<body>
<form action="contact2.php" method="post">
<input name="firstName" placeholder="firstName" type="text" size="30" />
<input name="lastName" placeholder="lastName" type="text" size="30" />
<input name="email" placeholder="email" type="text" size="30" />
<input name="submit" type="submit" value="Send This">
</form>
</body>
</html>
php代码
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$toEmail = 'myemail@mydomain.com';
$emailSubject = "Contact Form:";
$headers = ['From' => $email, 'Reply-To' => $email];
$body = "Name: $firstName $lastName";
mail($toEmail, $emailSubject, $body, $headers);
header("Location: index.html");
?>
结果:邮件未发送(或接收),状态为 302 重定向,不知道为什么。
删除行header("Location: index.html");
它将解析 302 状态并将 return 200.
我有一个托管实例,仅用于测试上面的 2 个文件 index.html 和 contact.php
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Simple contact Form</title>
</head>
<body>
<form action="contact2.php" method="post">
<input name="firstName" placeholder="firstName" type="text" size="30" />
<input name="lastName" placeholder="lastName" type="text" size="30" />
<input name="email" placeholder="email" type="text" size="30" />
<input name="submit" type="submit" value="Send This">
</form>
</body>
</html>
php代码
<?php
$firstName = $_POST['firstName'];
$lastName = $_POST['lastName'];
$email = $_POST['email'];
$toEmail = 'myemail@mydomain.com';
$emailSubject = "Contact Form:";
$headers = ['From' => $email, 'Reply-To' => $email];
$body = "Name: $firstName $lastName";
mail($toEmail, $emailSubject, $body, $headers);
header("Location: index.html");
?>
结果:邮件未发送(或接收),状态为 302 重定向,不知道为什么。
删除行header("Location: index.html");
它将解析 302 状态并将 return 200.