Email php邮件未发送到电子邮件 登记表
这是用PHP发送邮件的函数:Email php邮件未发送到电子邮件 登记表,email,php,Email,Php,这是用PHP发送邮件的函数: <!DOCTYPE html> <html> <head> <link href="aadab.css" rel="stylesheet" type="text/css"> <link rel="icon" href="images/favicon.png"> </head> <body> <h2>REGISTRATION FORM</
<!DOCTYPE html>
<html>
<head>
<link href="aadab.css" rel="stylesheet" type="text/css">
<link rel="icon" href="images/favicon.png">
</head>
<body>
<h2>REGISTRATION FORM</h2>
<div id="form">
<?php
if(isset($_POST['submit']))
{
$name= $_POST['name'];
$phone= $_POST['phone'];
$email= $_POST['email'];
$college= $_POST['namecolg'];
$team= $_POST['team'];
$im= $_POST['im'];
$detail= $_POST['detail'];
$subject= 'Registration for aadab 2013';
if ( (empty($name)) || (empty($phone)) || (empty($email)) || (empty($college)) || (empty($detail)) )
{
echo '<p id="fillall">It is necessary that you fill at least the required fields that are marked with a star</p>';
}
else
{
$to= 'xyz@gmail.com';
$con= "<b>Registration Details:</b><br>"."Name: $name<br>"."Contact: $phone<br>"."Email: $email<br>"."College: $college<br>"."Team(if any): $team<br>"."Instant message: $im<br>"."Details of the event(s): $detail<br>";
$emsg= "Registration Details:\n\n"."Name: $name\n"."Contact: $phone\n"."Email: $email\n"."College: $college\n"."Team(if any): $team\n"."Instant message: $im\n"."Details of the event(s): $detail\n";
$msg = wordwrap($emsg,70);
$mailsend= mail($to, $subject, $msg);
if ($mailsend)
{
echo "<div class=\"regdet\"><b>Here is what you've submitted:</b><br><br>$con";
echo '<br>Congratulations! You have successfully registered! Click <a href="index.html">here</a> to continue.</div>';
}
else
{
echo '<div class="regdet"><br>OOPS! Something went wrong. Click <a href="form.php">here</a> to try again.</div>';
}
}
}
else
{?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" autocomplete="on" method="post">
<table>
<tr>
<th><label for="name">Your fullname*</label></th>
<td><input type="text" id="name" name="name" value="<?php echo $name; ?>" required></td>
</tr>
<tr>
<th><label for="phone">Your contact number*</label></th>
<td><input type="tel" id="phone" name="phone" value="<?php echo $phone; ?>" required></td>
</tr>
<tr>
<th><label for="email">Your email-id*</label></th>
<td><input type="email" id="email" name="email" value="<?php echo $email; ?>" required></td>
</tr>
<tr>
<th><label for="namecolg">Name of your college*</label></th>
<td><input type="text" id="namecolg" name="namecolg" value="<?php echo $college; ?>" required></td>
</tr>
<tr>
<th><label for="team">The name of your team<br>(if registering for a team event)</label></th>
<td><input type="text" id="team" name="team" value="<?php echo $team; ?>" ></td>
</tr>
<tr>
<th><label for="im">Bbm pin/iMessage id/Whatsapp<br>(if any, separate each id by a comma)</label></th>
<td><input type="text" id="im" name="im" value="<?php echo $im; ?>" ></td>
</tr>
<tr>
<th><label for="detail">Details of the event(s) you want to register for*</label></th>
<td><input type="text" id="detail" name="detail" value="<?php echo $detail; ?>" required></td>
</tr>
<tr><td colspan="2" style="text-align: center; padding: 40px 0px 0px 0px;"><input type="submit" name="submit" value="Register"></td</tr>
</table>
</form>
<?php } ?>
</div>
</body>
</html>
到
,主题
和消息
都是必需的参数。你错过了一个主题
标题
和参数
是可选的
有关如何使用
mail()
函数的更多详细信息,请参阅:如果您知道邮件设置为,并且服务器允许,请尝试发送测试电子邮件,以确保您的变量没有产生错误。这样做:
mail(to,subject,message,headers,parameters)
如果您不知道邮件已设置并启用,请执行以下操作:
首先,运行phpinfo()
并查看php.ini文件的路径。接下来,找一行写着“禁用功能”,看看它是否包含单词“邮件”。如果是这样,只需从此行中删除mail
关键字,即可启用mail()函数。如果您无法访问php.ini,您可能希望联系您的Web主机,询问他们是否可以手动为您启用它
但是,如果没有设置发送路径,则要使mail()正常工作将困难得多。如果是这种情况,您可能需要考虑使用第三方邮件程序,例如。就个人而言,我使用SwiftMailer,尽管php的mail()函数对我来说是启用的。在我看来,它使标题和其他事情变得更容易
基于失败的邮件()函数进行更新:
在这种情况下,运行phpinfo()代码>并查看第6行。它应该是配置文件(php.ini)路径
。然后使用提供的路径显示php.ini文件的内容,方法如下:
$test = mail('your@email.com', 'Test Email', 'Hope this works!');
if ( $test ) { echo 'Yay it worked!'; }
else { echo 'Oh no mail failed!'; }
然后,在文档中搜索禁用的\u功能
,查看邮件
是否在其中。如果没有,我猜您的服务器上还没有设置发送路径
WIN64的更新:
请尝试将其放入您的配置中:
echo str_replace("\n", '<br />', file_get_contents(php_ini_loaded_file()));
首先,mail()
函数无法检查电子邮件是否到达邮箱。
但是您的脚本在mail()
上返回了一个false,所以它在服务器端
- 您的(本地)服务器上是否有邮件服务器
- php能否连接到此邮件服务器(如果您正在运行windows服务器,请参阅php.ini smtp部分,或者查看linux邮件服务器的错误日志)
- 看看php的错误日志
是的,请查看两台服务器上禁用的函数的phpinfo()
。
如果您在共享服务器上,有时不允许发送邮件。
您很可能无法将邮件从本地域发送到另一个邮件服务器,因为这可能是一个不合格或非法的域(将被标记为垃圾邮件)
最后但并非最不重要的一点是,下载a,它更易于使用,而且您不必担心邮件标题您确定php.ini文件中允许使用mail()吗?您的机器上是否设置了邮件服务器,并且是否在php.ini中配置了它?是的。。在live server iv上,临时使用了此表单的新目录。。因为服务器已经包含一个现有的网站,该网站能够发送电子邮件而不会出现问题。。但是这张表格从不发送任何电子邮件。这是我第一次经历这样的事情——没有邮件失败。我已经更新了我的答案,并给出了在这种情况下应遵循的步骤。请检查更新的答案。我检查了,在[mail function]下我只能看到Win32的配置。。。我正在运行Win64。。。这会有问题吗?Win64实际上使创建发送路径变得更容易。我再次更新了我的答案,希望对你有所帮助!我听从了你的建议,但现在出现了一个新问题:邮件程序错误:无法实例化邮件功能。你用谷歌搜索了错误吗?如果不是,那么(对我们来说)先用谷歌搜索然后再问我们就容易多了;-)
echo str_replace("\n", '<br />', file_get_contents(php_ini_loaded_file()));
[mail function]
SMTP = mail.yourdomain.com
sendmail_from = admin@yourdomain.com