PHP和SMTP不一起工作
可能重复:PHP和SMTP不一起工作,php,mysql,smtp,Php,Mysql,Smtp,可能重复: 我正在学习如何通过电子邮件授权注册用户的教程。我在SMTP上遇到了一些问题。我不知道为什么,但脚本不会发送电子邮件。我不知道这是否是一个SMTP或什么问题。本教程来自2009年,因此可能与最新版本的php不完全兼容。有人看到导致问题的原因吗 <?php echo "<h1>Register</h1>"; $submit = filter_input(INPUT_POST, 'submit'); //form data $fullname =
我正在学习如何通过电子邮件授权注册用户的教程。我在SMTP上遇到了一些问题。我不知道为什么,但脚本不会发送电子邮件。我不知道这是否是一个SMTP或什么问题。本教程来自2009年,因此可能与最新版本的php不完全兼容。有人看到导致问题的原因吗
<?php
echo "<h1>Register</h1>";
$submit = filter_input(INPUT_POST, 'submit');
//form data
$fullname = strip_tags (filter_input(INPUT_POST, 'fullname'));
$username = strtolower(strip_tags (filter_input(INPUT_POST, 'username')));
$password = strip_tags(filter_input(INPUT_POST, 'password'));
$repeatpassword = strip_tags(filter_input(INPUT_POST, 'repeatpassword'));
$date = date("Y-m-d");
$email = strtolower(strip_tags (filter_input(INPUT_POST, 'email')));
if ($submit)
{
//open database
$connect=mysql_connect("localhost","root","myrealpasswordwouldgohere");
mysql_select_db("phplogin");
$namecheck = mysql_query("SELECT username FROM users WHERE username='$username'" );
$count = mysql_num_rows($namecheck);
if($count!=0)
{
die("Username already taken, please choose another");
}
//check for existence
if($fullname&&$username&&$password&&$repeatpassword)
{
if ($password==$repeatpassword)
{
//check char length of username and fullname
if (strlen($username)>25||strlen($fullname)>25)
{
echo "Length of username or full name is too long!";
}
else
{
//check password length
if (strlen ($password)>25 || strlen ($password)<6)
{
echo "Password must be between 6 and 25 characters";
}
else
{
$password = md5($password);
//register user
//generate random number
$random = rand(23456789,98765432);
$queryreg = mysql_query("INSERT INTO users VALUES ('','$fullname','$username','$password','$email','$date','$random','0')");
die ("You have been registered! Check your email to activate your account to activate your account.");
$lastid = mysql_insert_id();
//send activation email
$to = $email;
$subject = "Activate your Account";
$headers = "From: ryansinclair14@gmail.com";
$server = "smtp.gmail.com";
ini_set("SMTP","smtp.gmail.com");
$body = "
Hello $fullname,\n\n
You need to activate you account with the link below:
http://localhost/academy/loginsession/activate.php?id=$lastid&code=$random \n\n
Thanks!
";
//function to send email
mail($to, $subject, $body, $headers);
die("You have been registered! Check your email to activate your account.");
}
}
}
else echo "Your passwords do not match";
}
else echo "Please fill in <b>all</b> fields!";
}
?>
<p>
<html>
<form action='register.php' method='POST'>
<table>
<tr>
<td>
Your full name:
</td>
<td>
<input type='text' name='fullname' value='<?php echo $fullname;?>'>
</td>
</tr>
<tr>
<td>
choose a username:
</td>
<td>
<input type='text' name='username' value='<?php echo $username;?>'>
</td>
</tr>
<tr>
<td>
Choose a password:
</td>
<td>
<input type='password' name='password'>
</td>
</tr>
<tr>
<td>
Repeat your password:
</td>
<td>
<input type='password' name='repeatpassword'>
</td>
</tr>
<tr>
<td>
Email:
</td>
<td>
<input type='text' name='email'>
</td>
</tr>
<table>
<p>
<input type='submit' name='submit' value='Register'>
</form>
您无法正确配置smtp。您无法提供密码和用户名
你可以通过下面的链接
您可以将phpmailer用于smtp邮件
我确信,如果您使用的是gmail服务器,您将需要正确地进行身份验证
谷歌弹出了一些看起来可能有用的东西
试试这个。可能需要包括Mail.php
的完整路径,无论安装在何处。我一直在查看该页面,哪个部分配置不正确?我添加了这些部分,但仍然不起作用……你在使用PEAR吗?php邮件功能无法与gmail一起使用。我没有收到错误,只是没有发送电子邮件。我相信我使用的是PEAR,但我不确定它是否如Pradeep Sanjaya所建议的那样,是随我通过XAMPUSE PHPMailer安装php而来的!完整路径的确切含义是什么?安装在正常位置我想我已经安装好了你认为你已经安装好了吗?你呢?在你的php文件夹中有一个pear
文件夹吗?是的,我得到了这个文件夹并包含了mail.php…仍然不工作
<?php
require_once "Mail.php";
$from = "ryansinclair14@gmail.com";
$to = "ryansinclair14@gmail.com";
$subject = "Test";
$body = "Hello World";
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "ryansinclair14";
$password = "PASSWORD";
$headers = array ('From' => $from,
'To' => $to,
'Subject' => $subject);
$smtp = Mail::factory('smtp',
array ('host' => $host,
'port' => $port,
'auth' => true,
'username' => $username,
'password' => $password));
$mail = $smtp->send($to, $headers, $body);
if (PEAR::isError($mail)) {
echo("<p>" . $mail->getMessage() . "</p>");
} else {
echo("<p>Message successfully sent!</p>");
}
?>