[PHP] A couple of things.
I know I'm on the right track and all, but then I hit snags in my code and I can't figure out what goes wrong.
First:
PHP Code:
Warning: mail() [function.mail]: SMTP server response: 550 Access denied - Invalid HELO name (See RFC2821 4.1.1.1) in C:\AppServ\www\test\includes\forgottenpassword.php on line 44
I'm using ini_set() to set the SMTP server, sendmail_from, and SMTP port.
SMTP: mail.myweb.com
sendmail_from: admin@myweb.com
SMTP port: 25
There is an active mail server for it, what else do I need?
Second:
Trying to make an automated script for changing character name using a select option for multiple types of name change (regular name change, and adding ^# colors)
PHP Code:
<form action="index.php?act=userpanel&do=changechname" method="post">
<table width="350" align="center" height="60" border="0" style="font-weight:bold; color:#FF3300;">
<p>Changing your character name will deduct Tokens from your account depending on your choice. <br />
Please be sure you want to do this as this will not be refunded. <br />
The color will be added to your name automatically. <br />
No need to put in the "^" <br />
Ex: Type = Red Name, New Name = test <br />
Result = ^1test</p>
<tr><td align="left"><?php echo $admingmp['12'].' :'; ?></td><td align="right"><select name="type" class="tbl_colbor">
<option value="0">Name Change - 50 Tokens</option>
<option value="1">Red Name - 30 Tokens</option>
<option value="2">Pink Name - 100 Tokens</option>
</select></td></tr>
<tr><td align="right"><?php echo $admingmp['2'].' :'; ?></td><td align="right"><input type="text" name="oldname" class="tbl_colbor" /></td></tr>
<tr><td align="right"><?php echo $admingmp['3'].' :'; ?></td><td align="right"><input type="text" name="newname" class="tbl_colbor" /></td></tr>
<tr><td></td><td width="130" align="right"><input type="submit" name="changechname" align="right" value="<?php echo $userpanel['2']; ?>" /></td></tr>
</table>
</form>
<div class="tbl_errmes">
<?php
if(isset($_POST['changechname'])){
$checktokens = mssql_query("SELECT Tokens FROM Account WHERE UserID='".$_SESSION['user']."'");
$type = anti_injection($_POST['type']);
if($type == 0)
{
if(mssql_result($checktokens, 0, 'Tokens')<50)
{
echo $userpanel['31'];
}
}
elseif($type == 1)
{
if(mssql_result($checktokens, 0, 'Tokens')<30)
{
echo $userpanel['31'];
}
}
elseif($type == 2)
{
if(mssql_result($checktokens, 0, 'Tokens')<100)
{
echo $userpanel['31'];
}
}
else{
$oldname = anti_injection($_POST['oldname']);
$newname = anti_injection($_POST['newname']);
$type = anti_injection($_POST['type']);
$charsql = mssql_query("SELECT * FROM Character WHERE Name='$oldname' AND AID='".$_SESSION['AID']."'");
if($oldname&&$newname){
if(mssql_num_rows($charsql)<>0){
if($type == 0)
{
mssql_query("UPDATE Character SET Name='$newname' WHERE Name='$oldname' AND AID='".$_SESSION['AID']."'");
mssql_query("UPDATE Account SET Tokens = Tokens - 50 WHERE UserID='".$_SESSION['user']."'");
echo $admingmp['7'];
}
elseif($type == 1)
{
mssql_query("UPDATE Character SET Name='^1$newname' WHERE Name='$oldname' AND AID='".$_SESSION['AID']."'");
mssql_query("UPDATE Account SET Tokens = Tokens - 30 WHERE UserID='".$_SESSION['user']."'");
echo $admingmp['7'];
}
elseif($type == 2)
{
mssql_query("UPDATE Character SET Name='^5$newname' WHERE Name='$oldname' AND AID='".$_SESSION['AID']."'");
mssql_query("UPDATE Account SET Tokens = Tokens - 100 WHERE UserID='".$_SESSION['user']."'");
echo $admingmp['7'];
}
}else{
echo $admingmp['6'];
}
}else{
echo $admingmp['5'];
}
}
}
?>
</div>
This one, the check Tokens works, but then even with enough Tokens, the name change doesn't work, and no error shows.
Thanks if you can help.
Re: [PHP] A couple of things.
First thing:
Use PHPMailer
You probably need to set authentication in PHPMailer before you can use your mail server.
Second thing:
It does nothing because there's an "else" after the last elseif.
And since $type is always set and either 0, 1 or 2 in this case, it will never go into the else.
http://puu.sh/1sZiJ
Also, shouldn't you check if the new name is already in use?
And what if I fill in ^5SuperWaffle at the normal name change for 50 tokens?
Re: [PHP] A couple of things.
Quote:
Originally Posted by
SuperWaffle
First thing:
Use
PHPMailer
You probably need to set authentication in PHPMailer before you can use your mail server.
That depends on what the mail function is used for. If it's used as a simple and small notification mailer, it's better performance to write your own wrapper to PHP's mail function considering PHPMailer does have quite an overhead. Then again, if you're going with multiple recipients, attachments and so on, PHPMailer is the most easy way to go.
@TS
You need to enter the SMTP credentials in PHP.ini (username (usually equals email address) and password), the SMTP server is simply not an open relay server.
Re: [PHP] A couple of things.
Thanks, I fixed the Name Change script and added in a check to see if the name is already taken or not.
Looks like I'm either going to have to take out the email function and use secret question and answer stuff, or modify it heavily to use PHPMailer or something similar.
Re: [PHP] A couple of things.
The first error is probably a result of credentials to an SMTP server, Google actually allows you to use GMAIL as you SMTP server here is the information to that:
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "Youremail@gmail.com";
$password = "YourPasswordtoGmail";
Re: [PHP] A couple of things.
Quote:
Originally Posted by
deathtaker26
The first error is probably a result of credentials to an SMTP server, Google actually allows you to use GMAIL as you SMTP server here is the information to that:
$host = "ssl://smtp.gmail.com";
$port = "465";
$username = "Youremail@gmail.com";
$password = "YourPasswordtoGmail";
I think he already fixed the issue.
Just FYI, Google will block your GMail account (or the usage of their SMTP server) in no-time if you're using it to send status/request emails. (Tried it once.)