By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,009 Members | 2,866 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,009 IT Pros & Developers. It's quick & easy.

Notice: Undefined index:

P: 2
Can anyone help me,
i am creating a website and am using a php script that recomends the website to other people. I keep getting the same error and can not work out why. The error is:

Notice: Undefined index: FriendName in D:\Yan\Over_8\SendEmail.php on line 4, Notice: Undefined index: FriendEmail in D:\Yan\Over_8\SendEmail.php on line 5, Notice: Undefined index: Name in D:\Yan\Over_8\SendEmail.php on line 6, Notice: Undefined index: Email in D:\Yan\Over_8\SendEmail.php on line 7, Notice: Undefined index: emailtext in D:\Yan\Over_8\SendEmail.php on line 8.

I have changed in the php.ini file the smtp setting to divert the emails to the my exchange server as this server is seprate and also added the server to the relay list. I can send email from this script still but only externally. I have also tried adding this: error_reporting(E_ALL ^ E_NOTICE); .into the script to hide the errors. It does hide them but the script does not work sending email externally.
My script is:
[PHP]
<title>Recommend This Site</title>

<?php
$FriendName = $_POST['FriendName'];
$FriendEmail = $_POST['FriendEmail'];
$Name = $_POST['Name'];
$Email = $_POST['Email'];
$emailtext = $_POST['emailtext'];
$string = $_SERVER['QUERY_STRING'];

?>
<html><head>
<script language="JavaScript" type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
var p,i,x; if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_validateForm() { //v4.0
var i,p,q,nm,test,num,min,max,errors='',args=MM_valida teForm.arguments;
for (i=0; i<(args.length-2); i+=3) { test=args[i+2]; val=MM_findObj(args[i]);
if (val) { nm=val.name; if ((val=val.value)!="") {
if (test.indexOf('isEmail')!=-1) { p=val.indexOf('@');
if (p<1 || p==(val.length-1)) errors+='- '+nm+' must contain an e-mail address.\n';
} else if (test!='R') { num = parseFloat(val);
if (isNaN(val)) errors+='- '+nm+' must contain a number.\n';
if (test.indexOf('inRange') != -1) { p=test.indexOf(':');
min=test.substring(8,p); max=test.substring(p+1);
if (num<min || max<num) errors+='- '+nm+' must contain a number between '+min+' and '+max+'.\n';
} } } else if (test.charAt(0) == 'R') errors += '- '+nm+' is required.\n'; }
} if (errors) alert('The following error(s) occurred:\n'+errors);
document.MM_returnValue = (errors == '');
}
//-->
</script>
</head>
<body bgcolor="#999999">
<?php
if (!$FriendEmail) {
?>
<br>
<form name="form1" onsubmit="MM_validateForm('Name','','R','Email','' ,'RisEmail','FriendName','','R','FriendEmail','',' RisEmail');return document.MM_returnValue" action="" method="POST">
<div align="center">
<table width="427" border="0" cellspacing="0" cellpadding="3">
<tr>
<td width="63" align="right" valign="top"> </td>
<td width="5"><font face="Verdana" size="2"> </font></td>
<td width="138"><font face="Verdana" size="2" color="#FFFFFF">Name: </font> </td>
<td width="216"> <font face="Verdana" size="2" color="#FFFFFF">E-mail:</font></td>
</tr>
<tr>
<td align="right" valign="top">
<font face="Verdana" size="2" color="#FFFFFF">You:</font></td>
<td> </td>
<td>
<font face="Verdana">
<input type="text" name="Name" size="18"><font size="2"> </font></font>
</td>
<td>
<font face="Verdana">
<input type="text" name="Email" size="21"><font size="2"> </font></font>
</td>
</tr>
<tr>
<td align="right" valign="top">
<font face="Verdana" size="2" color="#FFFFFF">Friend:</font></td>
<td> </td>
<td>
<font face="Verdana">
<input type="text" name="FriendName" size="18"><font size="2"> </font>
</font>
</td>
<td>
<font face="Verdana">
<input type="text" name="FriendEmail" size="21"><font size="2"> </font>
</font>
</td>
</tr>
<tr>
<td align="right" valign="top">
<font face="Verdana" size="2" color="#FFFFFF">Message:</font></td>
<td> </td>
<td colspan="2">
<font face="Verdana">
<textarea name="emailtext" cols="38" rows="6" style="font-family: Trebuchet MS; font-size: 10pt">
I found this great website and I believe you would be interested in it.
Here is the link to that Website: http://www.number1yan.co.uk
</textarea><font size="2"> </font></font>
</td>
</tr>
<tr>
<td align="right"> </td>
<td><font face="Verdana" size="2"> </font> </td>
<td>
<font face="Verdana">
<input type="submit" value="Send Message" name="Submit"><font size="2"> </font>
</font>
</td>
<td> </td>
</tr>
</table>
</div>
</form>
<?php
}
else {
if ($FriendEmail) { mail( $FriendEmail, "Message from $Name", "$FriendName, \n\n".$emailtext ."\n\n$Name", "From: $Email");

}


echo "<center><br><br><font color=FFFFFF><font face=Verdana size=2>Thank you <font color=000000>$Name</font><font color=000000>.
<p><br>
<font color=FFFFFF> The email has been sent to <font color=000000>$FriendName</font><font color=000000>.
<p><br>
<br><a href='javascript:window.close();'>Close this window</a></font><p>
<font face=Verdana size=2></a></font></p>";
}
?>
<p> </p>
</body>
</html>
[/PHP]

Can anyone help please, my email is: removed@readthefaq.com.
Thanks
Apr 28 '07 #1
Share this Question
Share on Google+
3 Replies


code green
Expert 100+
P: 1,726
Your POST array contains the names of your HTML enitities. You have named the textboxes Email, Name etc. But you are trying to read FriendEmail, FriendName. And please use tags when submitting code.
Apr 28 '07 #2

P: 2
Your POST array contains the names of your HTML enitities. You have named the textboxes Email, Name etc. But you are trying to read FriendEmail, FriendName. And please use tags when submitting code.
So how will i fix this problem?
Apr 28 '07 #3

pbmods
Expert 5K+
P: 5,821
So how will i fix this problem?
Easy. Just enclose your code in PHP BBCode tags as described in the guidelines box to the right of the input when posting your code.

Oh. How to fix the problem in your code.

[PHP]
else {
if ($FriendEmail) { mail( $FriendEmail, "Message from $Name", "$FriendName, \n\n".$emailtext ."\n\n$Name", "From: $Email");

} // <-- Should this curly brace be here?


echo "<center><br><br><font color=FFFFFF><font face=Verdana size=2>Thank you <font color=000000>$Name</font><font color=000000>.
[/PHP]
Apr 28 '07 #4

Post your reply

Sign in to post your reply or Sign up for a free account.