我正在使用 WAMP 服务器 2.4。我想向我的 gmail 帐户发送邮件。我用于相同的代码如下所示。我阅读了一些论坛,他们建议我对 php.ini 文件进行更改。但这不是永久解决方案。还有一些人建议 mail() 不适用于 gmail 吗?有什么解决办法吗?
<?php
//Checking if entries are ok
if(isset($_POST['submit']))
{
if(isset($_POST['username']))
$id = $_POST['username'];
else
echo "Cannot be blank";
//ensuring mail goes to registered user
$query="SELECT * FROM table1 WHERE id = '$id' ";
$result= mysql_query($query,$con);
if (!($result) )
{
die('Error: ' . mysql_error($con));
}
else
{
$values = mysql_fetch_array($result);
}
// Sending mail...
if(mysql_num_rows($result)== 1)
{
if(isset($_POST['email']))
$to= $_POST['email'];
else
echo "invalid email";
$msg = 'Name :' .$values['name'] ."\n"
.'Id:' .$values['id']."\n"
.'Email:' .$values['email']."\n"
."Your password is:" . $values[password];
mail($to,"Forget your Password",$msg);
header('location: sent_mail.php');
}
else
echo "Verify your username again";
}
else{
echo "sending failed";
header('location: forget_password.php');
exit(0);
}