Undefined Variable Error

This is where you share YOUR scripts with others

Moderators: macek, egami, gesf

Teena
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 30, 2011 9:52 pm

Undefined Variable Error

Postby Teena » Wed Sep 14, 2011 10:06 pm

Hi,
while i'm executing my php code i'm getting error as undefined variable.Pls do notify the mistakes i've made.Herewith i'm attaching my codings.its urgent.......

Thanks in advance.
mail.php

<?php
$toaddress = 'myaddress@website.com' . ', ';
$toaddress .= 'myaddress2@website.com';

mail_attachment("$toaddress", "$first_name", "$last_name", "$username", "$email", "$telephone","$address");


function mail_attachment ($from , $to, $subject, $first_name, $last_name, $username, $email, $telephone,$address)
{

$email_from = $from;
$email_subject = $subject;
$email_username =$username;
$email_telephone=$telephone;
$email_address=$address;
$email_to = $to;

$headers = "From: ".$email_from;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";


$email_username.= $msg_txt ;
$email_message .= " \n\n".
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Username :" . $email_username . "\n\n";

$email_telephone .= $msg_txt;
$email_message .= ".\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Telephone :" . $email_telephone . "\n\n";
$email_address .= $msg_txt;
$email_message .= ".\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Address :" . $email_address . "\n\n";

$data = chunk_split(base64_encode($data));

$email_message .= "--{$mime_boundary}\n" .
"Content-Type: {$fileatt_type};\n" .
" name=\"{$fileatt_name}\"\n" .
//"Content-Disposition: attachment;\n" .
//" filename=\"{$fileatt_name}\"\n" .
"Content-Transfer-Encoding: base64\n\n" .
$data . "\n\n" .
"--{$mime_boundary}--\n";


$ok = @mail($email_to,$email_subject, $email_message, $headers );

if($ok) {
echo "<font face=verdana size=2>The file was successfully sent!</font>";
} else {
die("Sorry but the email could not be sent. Please go back and try again!");
}
}

?>

sendmail.php

<?php
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$username=$_REQUEST['username'] ;
$password=$_REQUEST['password'];
$confirm_password=$_REQUEST['confirm_password'];
$email = $_REQUEST['email'] ;
$telephone = $_REQUEST['telephone'] ;
$address=$_REQUEST['address'];
if (isset($_REQUEST['submit']))
{
if (!$_REQUEST['firstname']
| !$_REQUEST['lastname']
| !$_REQUEST['username']
| !$_REQUEST['password']
| !$_REQUEST['confirm_password']
| !$_REQUEST['email']
| !$_REQUEST['telephone']
| !$_REQUEST['address'] )
{
die('You did not complete all of the required fields');
}
if ($_REQUEST['password'] != $_REQUEST['confirm_password'])
{
die('Your passwords did not match. ');
}
}
?>
<?php include("mail.php");?>

lokanath7
New php-forum User
New php-forum User
Posts: 139
Joined: Mon Nov 15, 2010 12:11 am

Re: Undefined Variable Error

Postby lokanath7 » Thu Sep 15, 2011 2:43 am

ur calling func no. of argument is not the same as the defined func argument...
chk it and arrange them in right order...

Teena
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 30, 2011 9:52 pm

Re: Undefined Variable Error

Postby Teena » Thu Sep 15, 2011 11:47 pm

sry i didn't get you.......can you pls elaborate it?

NigelRen
php-forum Active User
php-forum Active User
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Undefined Variable Error

Postby NigelRen » Fri Sep 16, 2011 12:07 am

I think they are saying that your call to mail_attachment is only passing 7 values, and yet you define the function as needing 9 values. So for example - the first value you pass is toaddress, whereas the functions first parameter is $from.
But also - you only define $toaddress - but your passing $first_name and so on. Are you sure that all these values are being set in the rest of your code?

Teena
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 30, 2011 9:52 pm

Re: Undefined Variable Error

Postby Teena » Sun Sep 18, 2011 10:14 pm

Thank u for clarifying my doubt.........
I've rectified my mistake....but still its not sending any mail.

I need to get the registration form data into my mail account.Could you please help me? :help:

NigelRen
php-forum Active User
php-forum Active User
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Undefined Variable Error

Postby NigelRen » Sun Sep 18, 2011 11:43 pm

OK - can you post the code you have now. This helps in trying to sort problems out.

Teena
New php-forum User
New php-forum User
Posts: 7
Joined: Tue Aug 30, 2011 9:52 pm

Re: Undefined Variable Error

Postby Teena » Mon Sep 19, 2011 1:23 am

Here is my code.......

mail1.php


<?php
$to = 'myaddress@website.com' . ', ';
$to .= 'myaddress2@website.com';

mail_attachment("$from","$to","$subject","$firstname", "$lastname", "$username", "$email", "$telephone","$address");


function mail_attachment ($from , $to, $subject, $firstname, $lastname, $username, $email, $telephone, $address)
{
$email_from = $from;
$email_subject = $subject;
$email_username =$username;
$email_telephone=$telephone;
$email_address=$address;
$email_to = $to;

$headers = "From: ".$email_from;
$semi_rand = md5(time());
$mime_boundary = "==Multipart_Boundary_x{$semi_rand}x";
$headers .= "\nMIME-Version: 1.0\n" .
"Content-Type: multipart/mixed;\n" .
" boundary=\"{$mime_boundary}\"";


$email_username.= $msg_txt ;
$email_message .= " \n\n".
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Username :" . $email_username . "\n\n";

$email_telephone .= $msg_txt;
$email_message .= ".\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Telephone :" . $email_telephone . "\n\n";
$email_address .= $msg_txt;
$email_message .= ".\n\n" .
"--{$mime_boundary}\n" .
"Content-Type:text/html; charset=\"iso-8859-1\"\n" .
"Content-Transfer-Encoding: 7bit\n\n" .
"Address :" . $email_address . "\n\n";

$data = chunk_split(base64_encode($data));

$ok = @mail($email_to,$email_subject, $email_message, $headers );

if($ok)
{
echo "<font face=verdana size=2>The file was successfully sent!</font>";
}
else
{
die("Sorry but the email could not be sent. Please go back and try again!");
}
}
?>

sendmail.php


<?php
$firstname = $_REQUEST['firstname'] ;
$lastname = $_REQUEST['lastname'] ;
$username=$_REQUEST['username'] ;
$password=$_REQUEST['password'];
$confirm_password=$_REQUEST['confirm_password'];
$email = $_REQUEST['email'] ;
$telephone = $_REQUEST['telephone'] ;
$address=$_REQUEST['address'];
if (isset($_REQUEST['submit']))
{
if (!$_REQUEST['firstname']
| !$_REQUEST['lastname']
| !$_REQUEST['username']
| !$_REQUEST['password']
| !$_REQUEST['confirm_password']
| !$_REQUEST['email']
| !$_REQUEST['telephone']
| !$_REQUEST['address'] )
{
die('You did not complete all of the required fields');
}
if ($_REQUEST['password'] != $_REQUEST['confirm_password'])
{
die('Your passwords did not match. ');
}
}
?>
<?php include("mail1.php");?>


Since i'm new to PHP,i don't know whether the codings are correct.....
Thanks in advance....

NigelRen
php-forum Active User
php-forum Active User
Posts: 450
Joined: Fri Aug 05, 2011 9:53 am

Re: Undefined Variable Error

Postby NigelRen » Mon Sep 19, 2011 11:39 pm

The way I usually approach problems like this is to look at the function which is failing and then comment out some of the stuff that is used to set the variables for it. Even hard coding some of the values just to test the functionality.
So comment everything from after

Code: Select all

$email_username.= $msg_txt ;


up to the point of sending the e-mail

Code: Select all

$ok = @mail($email_to,$email_subject, $email_message, $headers );


If this works, then uncomment lines from the top till you find out where it stops working - then you should be able to work out what you intended as opposed to what's happening.

Sometimes with this approach you have to put your own values in - so maybe putting in a fixed value for email_to as

Code: Select all

$email_to = 'working@address.com';

to ensure that you can test it. Just remember to remove them before putting the code in live.


Return to “Your Scripts”

Who is online

Users browsing this forum: No registered users and 1 guest

cron