Re: Mail function
| From: | Zhimmy Kanata | Date: | Thu, 05 Apr 2007 18:42:54 +0000 |
| Subject: | Re: Mail function | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-252096@lists.php.net to get a copy of this message | ||
Hi,
Tried it...but it didn't work...Not sure why. I am using a respectable ISP and they are
looking at the problem although they tend to take their time.
I figure I must not be passing the variable. I will post my entire code.
For all those that help again thank you.
<?php
require("config.php");
require("functions.php");
//echo some styles to spice it up...
echo "
<style>
body
{
background: #131313;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
.register_box
{
border: 1px solid #323232;
background: #202020;
font-family: Verdana, Arial;
font-weight: bold;
font-size: 9px;
color: #FFFFFF;
}
</style>
";
switch($_GET['action'])
{
case "new":
//--------------------------------------
//[New Registration]
//--------------------------------------
if(!isset($_POST['register']))
{
echo "
<form action='register.php?action=new' method='POST'>
Username: <br />
<input type='text' name='username' class='register_box'>
<br />
Email: <br />
<input type='text' name='email' class='register_box'>
<br />
Password: <br />
<input type='password' name='password' class='register_box'>
<br />
<input type='submit' name='register' value='New Registration!'
class='register_box'>
</form>
";
}
elseif(isset($_POST['register']))
{
$username = mysql_real_escape_string($_POST['username']);
$password = mysql_real_escape_string($_POST['password']);
$email = mysql_real_escape_string($_POST['email']);
$activation_code = generateCode(25);
$userq = "SELECT username FROM user_system WHERE username = '$username' LIMIT
1";
$emailq = "SELECT email FROM user_system WHERE email = '$email' LIMIT 1";
//put errors into an array
$errors = array();
if(empty($username))
{
$errors[] = "The username field was blank! <br />";
}
if(mysql_num_rows(mysql_query($userq)) > 0)
{
$errors[] = "The username given is already in use! Please try another one! <br
/>";
}
if(empty($password))
{
$errors[] = "The password field was blank! <br />";
}
if(empty($email))
{
$errors[] = "The email field was blank! <br />";
}
if(mysql_num_rows(mysql_query($emailq)) > 0)
{
$errors[] = "The email given is already in use! Please try another one! <br />";
}
if(count($errors) > 0)
{
foreach($errors as $err)
{
echo $err;
}
}
else
{
$sqlq = "INSERT INTO user_system (username, password, email, is_activated,
activation_code)";
$sqlq .= "VALUES ('$username', '".md5($password)."',
'$email', '0', '$activation_code')";
mysql_query($sqlq) or die(mysql_error());
echo "$email"; <----- As you can see I am echoing here...so it should be passed.
echo "Thanks for registering!
You will recieve an email shortly containing your validation code,
and a link to activate your account!";
mail($email, "New Registration, www.sitename.com", " I'm passing it here
Thanks for registering on SITE NAME.
Here are your login details:
Username: ".$username."
Password: ".$password."
In order to login and gain full access, you must validate your account.
Click here to validate:
http://www.sitename.com/register.php?action=activate&user=".$username."&code=".$activation_code."
Thanks!
[Webmaster]
");
}
}
break;
case "activate":
//--------------------------------------
//[Activate Account]
//--------------------------------------
if(isset($_GET['user']) && isset($_GET['code']))
{
$username = mysql_real_escape_string($_GET['user']);
if(mysql_num_rows(mysql_query("SELECT id FROM user_system WHERE username =
'$username'")) == 0)
{
echo "That username is not in the database!";
}
else
{
$activate_query = "SELECT is_activated FROM user_system WHERE username =
'$username'";
$is_already_activated = mysql_fetch_object(mysql_query($activate_query)) or die(mysql_error());
if($is_already_activated->is_activated == 1)
{
echo "This user is already activated!";
}
else
{
$code = mysql_real_escape_string($_GET['code']);
$code_query = "SELECT activation_code FROM user_system WHERE username =
'$username' LIMIT 1";
$check_code = mysql_fetch_object(mysql_query($code_query)) or die(mysql_error());
if($code == $check_code->activation_code)
{
$update = "UPDATE user_system SET is_activated = '1' WHERE username =
'$username'";
mysql_query($update) or die(mysql_error());
echo "User $username has been activated! Thanks! You may now login!";
}
else
{
echo "The activation code was wrong! Please try again!";
}
}
}
}
else
{
echo "No ID or user given to activate!";
}
break;
}
?>
Shafiq Rehman <rehmanms@gmail.com> wrote:
Hi,
What i understand is, you have written a new function for sending emails.
Are you passing all the variables to that function? If not, you have to
pass.
or you can use my function
// function declaration, This function can send only HTML emails
function sendMail ($toEmail, $subject, $message, $fromName, $fromEmail)
{
$header .= "From: $from_name <$fromEmail>\n";
$header .= "Reply-To: <$fromEmail>\n";
$header .= "MIME-Version: 1.0\n";
$header .= "Content-type: text/html; charset=us-ascii; format=flowed\n";
$header .= "Content-Transfer-Encoding: 7bit\n";
$header .= "X-Mailer: php\n\n";
mail($toEmail, $subject, $message, $header);
}
// variable values and usage
$toEmail = "shafiq@shafiq.pk";
$subject = "Hello, This is test";
$message = "Hellow Shafiq,
This is test
message
Regards
Shafiq";
$fromName = "Sender Name";
$fromEmail = "you@yourdomain.com";
sendMail ($toEmail, $subject, $message, $fromName, $fromEmail);
?>
--
Shafiq Rehman (ZCE)
http://www.phpgurru.com | http://shafiq.pk
On 4/5/07, Zhimmy Kanata wrote:
>
> Hi,
>
> I am working on a program to create a registration feature through a
> email notificaiton much like this list. For functional use but also for
> personal training.
>
> However, I can't seem to pass the variable into the mail function() ? If
> I echo the variable it displays it so it must be passing the variable down.
> If I enter in a fixed and workable email address where $email is then it
> works as well. So I am a little confused to this problem. I have other
> programs where I do this but I place the mail function within a new
> function(). However, when I do that it just barks back at me. Contacted my
> Hosting company they are investigating.
>
> Thanks in advance for your help...
>
> Here is the code..
>
> echo "$email";
> echo "Thanks for registering! <----- It does echo it.
> You will recieve an email shortly containing your validation code,
> and a link to activate your account!";
>
>
> mail($email, "New Registration, www.sitename.com", "
> Thanks for registering on SITE NAME.
> Here are your login details:
>
> Username: ".$username."
> Password: ".$password."
>
> In order to login and gain full access, you must validate your
> account.
>
> Click here to validate:
>
> http://www.sitename.com/login/register.php?action=activate&user=
> ".$username."&code=".$activation_code."
>
> Thanks!
>
> [Webmaster]
> ");
>
> I got the code from www.avengingsorrow.com to see all the code.
>
> Sorry about the HTML email. I am new to the list (first post) and I
> don't believe you can turn off HTML email in Yahoo.
>
> Thanks again in advance
>
> Zhimmy
>
>
> ---------------------------------
> Make free worldwide PC-to-PC calls. Try the new Yahoo! Canada Messenger
> with Voice
---------------------------------
All new Yahoo! Mail -
---------------------------------
Get a sneak peak at messages with a handy reading pane.