Log in

View Full Version : PHP Email Activation Link



devil_vin
08-26-2007, 02:15 PM
I have a code to send activation link to user email and click it for account activation. I am using PHPMailer for sending mail and configure SMTP authentication but email not sent yet and shown:

Mailer Error: Language string failed to load: data_not_accepted

I have put phpmailer.lang-en.php under htdocs folder already,so what mighht cause this error?Thanks....

The following is my form processing code:



<?php
ini_set("include_path", "path/to/language/file");
//Connect to mysql database
$conn = mysql_connect("localhost", "root", "") or die('Could not connect: ');
$db = mysql_select_db("movie_ticket_booking", $conn) or die('Could not select database');

//global variable
$table1 = "temp_members";
$table2 = "registered_member";

//Random confirmation code
$confirm_code = md5(uniqid(rand()));

//This code runs if the form has been submitted
if (isset($_POST['submit']))
{

// checks if the email address is alredy registered
//if (!get_magic_quotes_gpc())
//{
//$_POST['email'] = addslashes($_POST['email']);
//}
$emailcheck = $_POST['email'];
$check = mysql_query("SELECT email FROM $table2 WHERE email = '$emailcheck'") or
die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0)
{
die('Sorry, the email address' . $_POST['email'] . ' is already registered.');
}

// encrypt the password
$pass1 = md5($pass1);
//if (!get_magic_quotes_gpc())
//{
//pass1 = addslashes($pass1);
//$_POST['member_id'] = addslashes($_POST['member_id']);

//Insert record to database
$insert = mysql_query("INSERT INTO $table1(confirm_code,name,email,password,tel,address)
VALUES ('$confirm_code','" . $_POST['name'] . "','" . $_POST['email'] .
"', '" . $_POST['pass1'] . "','" . $_POST['tel'] . "','" . $_POST['address'] ."')")
or die(mysql_error());


// }

//if successfully inserted,send confirmation link to email
if ($insert)
{

echo "thank for your registration!";

require ("class.phpmailer.php");

$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "root";// SMTP username
$mail->Password = "";// SMTP password
$mail->SetLanguage("en","phpmailer/language");

//compose mail
$mail->From = "admin@localhost.com";
$mail->FromName = "Cinema Admin";
$mail->AddAddress($_POST['email']);
$mail->AddReplyTo("admin@localhost.com", "Cinema Admin");
$mail->Subject = 'Your confirmation link here';
$mail->Body = "Your confirmation link\r\n";
$mail->Body .= "Click on this link to activate your sccount\r\n";
$mail->Body .= "http://localhost/www/confirm.php?passkey=$confirm_code";


//send mail
if (!$mail->Send())
{
echo "Message was not sent <p>";
echo "Mailer Error: " . $mail->ErrorInfo;
exit;
}

echo "Message has been sent";
}

//if not found
else
{
echo "Not found your email in our database";
}

//if your email successfully sent
//if ($sentmail)
//{
//echo "Your confirmation link has been sent to your email address.";
//}

//else
//{
// echo "Cannot send confirmation link to your email address.";
//}

}
?>


sendmail portion in php.ini


[mail function]
; For Win32 only.
SMTP = localhost
smtp_port = 25

; For Win32 only.
sendmail_from = admin@localhost.com

thetestingsite
08-26-2007, 03:09 PM
Do you actually have a mail server installed on your server? If not, that would be the reason for your script failure. If you already do have a mail server, make sure that the user info for the account you are going to use to send the email with is correct in this portion of the code:



$mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "{USERNAME HERE}";// SMTP username
$mail->Password = "{PASSWORD HERE}";// SMTP password
$mail->SetLanguage("en","phpmailer/language");


Hope this helps.

devil_vin
08-26-2007, 03:58 PM
I am running Local SMTP Server Pro in my localhost server.My computer is listening to telnet localhost 25.

I had created an account admin@localhost.com under Outlook Express with following username and password which I specified in sendmail form and class.phpmailer.php sendmail portion.


mail = new PHPMailer();
$mail->IsSMTP();
$mail->Host = "localhost";
$mail->SMTPAuth = true;// turn on SMTP authentication
$mail->Username = "admin";// SMTP username
$mail->Password = "itc309";// SMTP password
$mail->SetLanguage("en","phpmailer/language");




/**
* Sets SMTP authentication. Utilizes the Username and Password variables.
* @var bool
*/
var $SMTPAuth = true;

/**
* Sets SMTP username.
* @var string
*/
var $Username = "admin";

/**
* Sets SMTP password.
* @var string
*/
var $Password = "itc309";


However,I can neither run my script nor send out mail through localhost account in Outlook Express...What went wrong actually??

thetestingsite
08-26-2007, 04:05 PM
Did you make the same user account in the actual SMTP Server software? If not, then there is your problem. Not sure exactly how you would do it, being that I never messed with the program before; but there should be something that talks about "Users" or "Accounts". In there, you should be able to add your user account and making the script work for you.

Hope this helps.

devil_vin
08-26-2007, 04:17 PM
That SMTP server software only allow me to cinfigure account under Outlook Express and I implement the same account setting under Outlook,send mail form and class.phpmailer.php

From Adress:admin@localhost
User Name:admin
Password:itc309
Incoming Server(POP3):localhost
Outgoing Server(SMTP):localhost

So,what might went wrong?thanks...

thetestingsite
08-26-2007, 04:23 PM
Let me download the software and I'll be able to troubleshoot this a bit more. Just a thought off the top of my head though, did you open the port 25 in your firewall/router? Other than that, I need to run some tests to try and recreate what you are experiencing.

devil_vin
08-26-2007, 04:27 PM
Thanks for your initiative.I can do telnet localhost 25 seems port is opened.

thetestingsite
08-26-2007, 04:46 PM
For some reason, the server software doesn't want to download and install on my computer properly; so I can't fully replicate your problem. Something that I am wondering; after looking at the documentation for phpmailer, is there a reason for this line?



$mail->SetLanguage("en","phpmailer/language");


All the examples I have seen in the documentation does not include this line. Perhaps try taking that out and see if that works.

//EDIT: This still doesn't explain the reason for your outlook express not sending out. The only thing I could recommend is either moving your script to a different server, or downloading a different mail server software (such as hMailServer (http://www.hmailserver.com)).

Hope this helps.

kbear
08-28-2007, 11:38 AM
I had created an account admin@localhost.com under Outlook Express with following username and password which I specified in sendmail form and class.phpmailer.php sendmail portion.

However,I can neither run my script nor send out mail through localhost account in Outlook Express...What went wrong actually??

i would be sticking to Outlook express and try getting the SMTP working through that first, what settings have you got in outlook express ? in SMTP Server Pro settings what settings have you put in there ... i noticed on the screen shots that it allows you to put in SMTP gateway settings .... what is in there ?

once you have outlook express running then you know that it all works and then i would focus on the php code ....