使用php使用邮件功能时不会发送电子邮件

时间:2016-01-17 11:23:01

标签: php html database email

我正在尝试在用户注册到此表单后向我的电子邮件地址(管理员)发送电子邮件确认!请问如何配置我的sendmail?我正在使用Xampp。代码正常,消息

  

电子邮件已发送

显示

但是当打开包含在$to变量中的电子邮件地址时,收件箱中没有任何电子邮件。这是我的代码:

<html >
<head>
<title></title>
</head>
<body>
<?php
print ("<form action='register.php' method='post'>
    <p>Name
        <input type='text' name='firstname'  />
    </p>
    <p>Surname
        <input type='text' name='lastname' />
    </p>
    <p>Username
        <input type='text' name='username' />
    </p>
    <p>Password
        <input type='password' name='password' />
        </p>
        <p>Email <input type='text' name='email'/>  </p>
      Enter your CV: <p> <textarea name='cv' cols='60' rows='50'></textarea> </p>


  <input type='submit'  value='Register'/>  
</form>
        ");

if( !($database=mysql_connect("localhost","root",""))||!(mysql_select_db("st_login",$database))  )
   print("Could not connect");

if(isset($_POST['firstname'] )&&isset($_POST['lastname'])&&isset($_POST['username'])&&isset($_POST['password'])
  &&isset($_POST['cv'])/*&&isset($_POST['notat'])&&isset($_POST['lendet'])*/&&isset($_POST['email'])){
$firstname=$_POST['firstname'];
$lastname=$_POST['lastname'];
$username=$_POST['username'];
$password=$_POST['password'];
$email=$_POST['email'];

$cv=$_POST['cv'];
/*
$notat=$_POST['notat'];
$lendet=$_POST['lendet'];
*/

$query = "INSERT INTO  login (firstname, lastname, username,password,cv,email) VALUES ('$firstname', '$lastname',
 '$username','$password','$cv','$email')";
}
if ( !empty($firstname)&&!empty($lastname)&&!empty($username) &&!empty($password)&&!empty($cv)&&!empty($email))
{
  if(!($result=mysql_query($query,$database)))
{
    print("Could not execute query");
    die (mysql_error());//ose error
}

$to='backa.elda123@gmail.com';
$subject='Asking for permission';
$body='There is another registered student waiting for your approval!';
$headers='From:<arbi.backa@gmail.com>';
if(mail($to,$subject,$body,$headers)){
  echo "mail sent to..";}
  else echo'errorr sending the email';
echo "YOU HAVE BEEN REGISTERED SUCCESSFULLY!PLEASE WAIT FOR THE ADMIN APPROVAL!";
}
else echo "Fill in all the blank fields";
mysql_close($database);
?>

</body>
</html>

1 个答案:

答案 0 :(得分:0)

对PHP mail函数使用情况进行故障排除已部分涵盖here

实际发送电子邮件后,将其视为垃圾邮件非常棒。

大多数电子邮件提供商不会将未经身份验证的电子邮件视为有效电子邮件,并将其视为垃圾邮件。 Gmail也不例外,您应该使用类似SMTP身份验证的功能。请至少检查以下其中一项:

  1. PHPMailer
  2. Tutorial