我创建了一个发送到电子邮件的 PHP 脚本。
仅发送一个字段(消息字段)时,该表单似乎可以正常工作,但是一旦添加了其他字段,该表单就会停止通过电子邮件发送到收件箱(但是该表单仍然可以正确触发并重新路由到Thankyou就好了。 )
这是我目前拥有的代码,这不起作用
<?php
$email = $_REQUEST['email'] ;
$name = $_REQUEST['name'] ;
$services = $_REQUEST['services'] ;
$message = $_REQUEST['message'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: feedback.html" );
}
elseif (empty($email) || empty($message)) {
header( "Location: error.html" );
}
else {
mail( "info@website.co.uk", "Message via your website!",
$name, $services, $message, "From: $email" );
header( "Location: thankyou.html" );
}
?>
这是以前的代码,这确实有效,但只显示消息
<?php
$email = $_REQUEST['email'] ;
$message = $_REQUEST['message'] ;
if (!isset($_REQUEST['email'])) {
header( "Location: feedback.html" );
}
elseif (empty($email) || empty($message)) {
header( "Location: error.html" );
}
else {
mail( "info@website.co.uk", "Message via your website!",
$message, "From: $email" );
header( "Location: thankyou.html" );
}
?>
这是表单的 HTML:
<form method="post" action="sendmail.php">
<label>Name:</label> <input name="name" type="text" /><br />
<label>Email:</label> <input name="email" type="text" /><br />
<label>What service do you require?:</label> <input name="services" type="text" /><br />
<label>Message:</label><br />
<textarea name="message" rows="15" cols="40">
</textarea><br />
<input type="submit" />
</form>