PHP重定向电子邮件联系人
我正在本地服务器上测试来自提交的联系人。dev.localhost 我得到的错误是PHP重定向电子邮件联系人,php,html,email,redirect,contact,Php,Html,Email,Redirect,Contact,我正在本地服务器上测试来自提交的联系人。dev.localhost 我得到的错误是 The requested URL /volunteer-success.php was not found on this server. 我是PHP新手。我正在尝试提交表单,通过电子邮件发送消息+姓名,然后将用户重定向到感谢屏幕 我的HTML如下 <form action="volunteer-submit.php" method="post" name="contact_form" data-par
The requested URL /volunteer-success.php was not found on this server.
我是PHP新手。我正在尝试提交表单,通过电子邮件发送消息+姓名,然后将用户重定向到感谢屏幕
我的HTML如下
<form action="volunteer-submit.php" method="post" name="contact_form" data-parsley-validate>
<textarea name="message" id="message" placeholder="Message" required></textarea>
<input type="text" placeholder="Your Name" id="name" name="name" required>
<input type="email" placeholder="Your Email Address" id="email" name="email" required>
<input type="submit" class="submit" value="Submit">
</form>
发送电子邮件的PHP如下所示
$to = "example@example.com";
$subject = 'Email';
$headers = 'From: no-reply@example.com' . "\r\n" .
'Reply-To: '.$_POST["email"]. "\r\n" .
"Content-Type: text/html; charset=ISO-8859-1\r\n".
'X-Mailer: PHP/' . phpversion();
$message = '<html><head><title></title></head><body>';
$message .= '<p>Hi Ben, </p>';
$message .= '<p>'.$_POST['message'].' </p>';
$message .= '<p>'.$_POST['email'];
$message .= '</body></html>';
mail($to, $subject, $message, $headers);
//Redirect
header("Location:volunteer-success.php"); /* Redirect browser */
?>
$to=”example@example.com";
$subject='Email';
$headers='发件人:否-reply@example.com' . “\r\n”。
“回复:”。$\u POST[“email”]。“\r\n”。
“内容类型:text/html;charset=ISO-8859-1\r\n”。
“X-Mailer:PHP/”。phpversion();
$message='';
$message.='你好,本,';
$message.=''.$\u POST['message'].';
$message.=''.$\u POST['email'];
$message.='';
邮件($to、$subject、$message、$headers);
//重定向
标题(“位置:志愿者成功.php”);/*重定向浏览器*/
?>
想知道为什么它没有重定向。我已将php文件与index.html文件一起保存到dev.localhost上
*使用的示例电子邮件我想您应该使用javascript重定向
<script>window.location.href="volunteer-success.php";</script>
window.location.href=“志愿者成功.php”;
因为,大多数时候php Header()都不起作用试试这个-
使用exit()代码>在标题()之后
因为在将页面重定向到另一个页面后,不应该执行标题下的代码
header("Location: ./volunteer-success.php"); /* Redirect browser */
exit();
还有一件事。检查前后文件中的空间
// Before shouldn't be any space
<?php
?>
// After shouldn't be any space as well
//Before不应该是任何空格
//之后也不应该有任何空间
享受你的代码吧!:) “在此服务器上找不到请求的URL/志愿者-success.php。”表示该文件在apt位置不可用。尝试对该文件执行绝对地址操作,例如:header(“Location:);Try to:header(“Location:/”志愿者成功.php”);或:header(“Location://志愿者成功.php”);是您在实际的志愿者提交.php文件中显示的代码,还是包含在其他文件中?@谢谢!/Location://志愿者成功.php"); 工作顺便说一句,在位置:
之后需要有一个空格,而您的示例代码中没有这个空格,这可能就是错误所在。要防止?>
之后出现空格,您可以忽略它。无论如何,PHP都会在文件末尾停止,所以根本不关闭PHP标记通常更安全(因为编辑器会自动添加换行符)。但如果是标题
。如果你用它来重定向,那么你需要全部检查,并且exit()
应该在header()
之后。嘿@魔术师知道为什么邮件不会发送吗?它带我到重定向页面,但没有发送电子邮件。我使用了一个正确的电子邮件,而不是上面使用的示例。如果配置正确,请尝试:然后尝试更改换行符(它基于您的服务器):“\r\n”用于windows服务器“\n”用于unix服务器,或者您尝试使用“而不是”来代替“谢谢”。这样做会成功的。
header("Location: ./volunteer-success.php");