我试图制作一份申请表,但它不起作用。我一直在网站上搜索一些答案,但没有运气。 - 我尝试了几种不同的脚本。
而且我认为我使用的是与我的联系表格几乎相同的PHP脚本,但只有$ mail,$ subject和$ message - 而且工作正常。
这是我的代码:
<?php
/* Set e-mail recipient */
$myemail = "IADDEDMYMAILHERE@hotmail.com";
/* Check all form inputs using check_input function */
$name = check_input($_POST['name'], "Enter your name");
$email = check_input($_POST['email'], "Enter a subject");
$birthday = check_input($_POST['birthday']);
$cloths = check_input($_POST['cloths'], "Write your message");
$currentclub = check_input($_POST['currentclub'], "Klub");
$coachphone = check_input($_POST['coachphone'], "Indtast din træners telefonnummer");
$team = check_input($_POST['team'], "Indtast dit nuværende holds navn");
$message = check_input($_POST['message'], "Du mangler motiveret ansøgning");
/* If e-mail is not valid show error message */
if (!preg_match("/([\w\-]+\@[\w\-]+\.[\w\-]+)/", $email))
{
show_error("E-mail address not valid");
}
/* Let's prepare the message for the e-mail */
$message = "
name: $name
E-mail: $email
Birthday: $birthday
Cloths: $cloths
Currentclub: $currentclub
Clubranking: $clubranking
Coachphone $coachphone
Clubhis: $clubhis
Team: $team
Attention: $attention
Message: $message
";
/* Send the message using mail() function */
mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);
/* Redirect visitor to the thank you page */
header('Location: kontakt.html');
exit();
/* Functions we used */
function check_input($data, $problem='')
{
$data = trim($data);
$data = stripslashes($data);
$data = htmlspecialchars($data);
if ($problem && strlen($data) == 0)
{
show_error($problem);
}
return $data;
}
function show_error($myError)
{
?>
<html>
<body>
<p>Please correct the following error:</p>
<strong><?php echo $myError; ?></strong>
<p>Hit the back button and try again</p>
</body>
</html>
<?php
exit();
}
?>
我的HTML代码:
<form class="email" action="application.php" method="post">
<div id="ansøgninger">
<h4>Name</h4> <input type="text" name="name">
<h4>Email</h4> <input type="text" name="email">
<h4>fødselsdag</h4> <input type="text" name="birthday">
<h4>Tøjstørrelse</h4>
<select name="cloths" size="1">
<option value="XS" name="cloths">XS</option>>
<option value="S" name="cloths">S</option>>
<option value="M" name="cloths">M</option>>
<option value="L" name="cloths">L</option>>
<option value="XL" name="cloths">XL</option>>
</select>
<h4>Nuværende klub</h4> <input type="text" name="currentclub">
<h4>Hvilken række spiller klubben i?</h4>
<select name="priority" size="1">
<option value="Low">Low</option>
<option value="Normal">Normal</option>
<option value="High">High</option>
<option value="Emergency">Emergency</option>
</select>
<br />
<h4>Nuværende træners telefonnummer</h4> <input type="text" name="coachphone">
<h4>Klubhistorik</h4> <input type="text" name="clubhis">
<h4>udvalgt hold?</h4> <input type="text" name="team">
<h4>Ting vi skal være opmærksomme på?</h4> <input type="text" name="attention">
<h4>Type</h4>
<select name="type" size="1">
<option value="update">Website Update</option>
<option value="change">Information Change</option>
<option value="addition">Information Addition</option>
<option value="new">New Products</option>
</select>
<br />
<h4>Message</p><textarea name="message" rows="6" cols="25"></textarea><br />
<input type="submit" value="Send"><input type="reset" value="Clear">
</form>
</div>
</div>
</div>
答案 0 :(得分:2)
您没有正确调用mail
:
mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);
联机帮助页面在此处:http://php.net/manual/en/function.mail.php - 您需要传递电子邮件地址;主题;和消息;有几个可选参数。您需要将所有文本连接到单个消息变量中,并将该变量传入,而不是每个不同的值:
mail ($myemail, 'Subject', $message);
答案 1 :(得分:1)
基本mail()
函数有3个参数,如此
mail(to, subject, message)
您也可以添加标题和其他参数。
将mail()
行更改为
mail($myemail, $email, $message);
答案 2 :(得分:0)
您阅读了邮件功能的文档, http://php.net/manual/en/function.mail.php
mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);
你在mail()
函数中传递的参数是错误的......
mail($myemail, $email, $message)
变量$myemail
应存储收件人的电子邮件,$email
应将主题存储在其中,$ message应包含您要发送的邮件。
答案 3 :(得分:0)
我相信错误看起来是使用你的mail()php函数,这个函数最多只需要5个参数
mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);
您似乎已在$ message变量中包含$ name,$ birthday,$ cloths,$ currentclub,$ clubranking,$ coachphone,$ clubhis,$ team,$ attention,$ message,因此无需再次包含这些内容在邮件功能中。
您的代码应该类似于:
$emailMessage = "
name: $name
E-mail: $email
Birthday: $birthday
Cloths: $cloths
Currentclub: $currentclub
Clubranking: $clubranking
Coachphone $coachphone
Clubhis: $clubhis
Team: $team
Attention: $attention
Message: $message
";
mail($myemail, $subject, $emailMessage);
有关mail()函数的使用,请参阅http://php.net/manual/en/function.mail.php。
答案 4 :(得分:0)
发送简单的电子邮件:
<?php
$txt = "First line of text\nSecond line of text";
// Use wordwrap() if lines are longer than 70 characters
$txt = wordwrap($txt,70);
// Send email
mail("somebody@example.com","My subject",$txt);
?>
发送包含额外标题的电子邮件:
<?php
$to = "somebody@example.com";
$subject = "My subject";
$txt = "Hello world!";
$headers = "From: webmaster@example.com" . "\r\n" .
"CC: somebodyelse@example.com";
mail($to,$subject,$txt,$headers);
?>
发送HTML电子邮件:
<?php
$to = "somebody@example.com, somebodyelse@example.com";
$subject = "HTML email";
$message = "
<html>
<head>
<title>HTML email</title>
</head>
<body>
<p>This email contains HTML Tags!</p>
<table>
<tr>
<th>Firstname</th>
<th>Lastname</th>
</tr>
<tr>
<td>John</td>
<td>Doe</td>
</tr>
</table>
</body>
</html>
";
// Always set content-type when sending HTML email
$headers = "MIME-Version: 1.0" . "\r\n";
$headers .= "Content-type:text/html;charset=iso-8859-1" . "\r\n";
// More headers
$headers .= 'From: <webmaster@example.com>' . "\r\n";
$headers .= 'Cc: myboss@example.com' . "\r\n";
mail($to,$subject,$message,$headers);
?>