HTML和PHP邮件应用程序未发送


HTML and PHP mail application not sending

我试图制作一个应用程序表单,但它不起作用。我一直在网站上搜索以找到一些答案,但运气不好。-我试过几种不同的剧本。

我的想法是,我使用的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="answersø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>

您没有正确调用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);

基本的mail()函数采用3个参数,如

mail(to, subject, message)

您也可以添加标题和其他参数。

mail()线路更改为

mail($myemail, $email, $message);

您阅读了邮件功能的文档,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应包含要发送的邮件。

我相信错误看起来是由于使用了您的mail()php函数,该函数最多只需要5个参数

mail($myemail, $name, $birthday, $cloths, $currentclub, $clubranking, $coachphone, $clubhis, $team, $attention, $message);

您似乎已经在$message变量中包含了$name、$birthy、$cloth、$currentclub、$clubraking、$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);

请参阅http://php.net/manual/en/function.mail.php了解mail()函数的用法。

请参阅邮件的示例代码。。https://stackoverflow.com/questions/20072751/write-the-email-code-for-upload-resume-in-contact-page-receive-the-email-in-php/20073275#20073275

发送一封简单的电子邮件:

<?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);
?>