jcdevelopment 03-24-2009, 05:10 PM Im not sure why i am getting this error of:
A PHP Error was encountered
Severity: Notice
Message: Undefined index: email
Filename: views/contact.php
Line Number: 14
Could it be that i am using "codeignitor"? I normally use "cake php" but decided to try this out. I use this code all of the time to send the client an email. Can anyone see if i am missing something?
<?php
error_reporting(0);
if ($_POST["email"]<>'') { //error line
$ToEmail = 'justin@ebby.com';
$EmailSubject = 'Vendor Sign Up ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<?php
} else {
?>
<form method="post" action="/page/display/thanks.php">
<label for="Name">Name:</label>
<br />
<input type="text" name="name" />
<br/>
<br />
<label for="email">Email</label>
<br />
<input type="text" name="email" />
<br />
<br />
Information:
<br />
<textarea rows="10" cols="40" name="info"></textarea>
<br /><br/>
<input name="Submit" type="submit" value="Submit" />
</form>
<?php
};
?>
Thanks for any help.
rafiki 03-24-2009, 05:20 PM Why are you using <>?
jcdevelopment 03-24-2009, 05:25 PM to tell you the truth, i went around looking for a simple contact to email php script. I found a few and kind of combined them. Everything seemed fine but i always got this error
syntax error, unexpected T_CONSTANT_ENCAPSED_STRING
so i looked around and adding <> seemed to stop it. I am a beginner in PHP so i have no idea why that works. Is there something i should do to avoid this?
thanks!
oesxyl 03-24-2009, 05:37 PM to tell you the truth, i went around looking for a simple contact to email php script. I found a few and kind of combined them. Everything seemed fine but i always got this error
so i looked around and adding <> seemed to stop it. I am a beginner in PHP so i have no idea why that works. Is there something i should do to avoid this?
thanks!
if(isset($_POST['email']) && !empty($_POST['email'])){
// code.
}
the message is a notice and come probably from framework since you have error_reporting(0). Change it to E_ALL to see what's happend.
I talk about post #1
best regards
jcdevelopment 03-24-2009, 05:43 PM I tried it and i have no errors, but i have no email sent as well. Not sure what its doing.
oesxyl 03-24-2009, 05:54 PM I tried it and i have no errors, but i have no email sent as well. Not sure what its doing.
add before error_reporting:
ini_set('display_errors',1);
I thought that is enabled, but maybe is not.
check to see what you have in $_POST after submit using print_r
best regards
jcdevelopment 03-24-2009, 06:11 PM hmmm.. still no errors or emails... here is what the code looks like now, am i doing it right?
<?php
ini_set('display_errors',1);
error_reporting(0);
if(isset($_POST['email']) && !empty($_POST['email'])){
$ToEmail = 'justin@ebby.com';
$EmailSubject = 'Vendor Sign Up ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<?php
} else {
?>
<form method="post" action="/page/display/thanks.php">
<label for="Name">Name:</label>
<br />
<input type="text" name="name" />
<br/>
<br />
<label for="email">Email</label>
<br />
<input type="text" name="email" />
<br />
<br />
Information:
<br />
<textarea rows="10" cols="40" name="info"></textarea>
<br /><br/>
<input name="Submit" type="submit" value="Submit" />
</form>
<?php
};
?>
Mouseman 03-24-2009, 06:18 PM It'd be better to have email address validation on $_POST['email']?
Can't see why the mail function's not working otherwise. Debug by commenting out the mail() function and echoing something useful to the screen, make sure the
if(isset($_POST['email']) && !empty($_POST['email'])){ line is doing its job right?
<Happy to be corrected, I'm new to things but I've just written a mailto script which works>
oesxyl 03-24-2009, 06:26 PM hmmm.. still no errors or emails... here is what the code looks like now, am i doing it right?
<?php
ini_set('display_errors',1);
error_reporting(0);
if(isset($_POST['email']) && !empty($_POST['email'])){
$ToEmail = 'justin@ebby.com';
$EmailSubject = 'Vendor Sign Up ';
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "Reply-To: ".$_POST["email"]."\r\n";
$mailheader .= "Content-type: text/html; charset=iso-8859-1\r\n";
$MESSAGE_BODY = "Name: ".$_POST["name"]."<br>";
$MESSAGE_BODY .= "Email: ".$_POST["email"]."<br>";
$MESSAGE_BODY .= "Info: ".$_POST["info"]."<br>";
mail($ToEmail, $EmailSubject, $MESSAGE_BODY, $mailheader) or die ("Failure");
?>
<?php
} else {
?>
<form method="post" action="/page/display/thanks.php">
<label for="Name">Name:</label>
<br />
<input type="text" name="name" />
<br/>
<br />
<label for="email">Email</label>
<br />
<input type="text" name="email" />
<br />
<br />
Information:
<br />
<textarea rows="10" cols="40" name="info"></textarea>
<br /><br/>
<input name="Submit" type="submit" value="Submit" />
</form>
<?php
};
?>
$mailheader = "From: ".$_POST["email"]."\r\n";
$mailheader .= "To ".$ToEmail."\r\n";
and echo $mailheader to see how it look.
seems ok. mail return true or false, check if is true.
best regards
rafiki 03-24-2009, 06:39 PM Check to see if the mails being sent to!
if(mail($to, $subject, $body, $add_headers){
echo 'Job Done!';
}else{
echo 'Error Sending Mail!';
}
obviously change the $var names to your actual variable name.
jcdevelopment 03-24-2009, 10:27 PM Thanks for all of the help, but i was able to look around and CI has some built in form stuff... here was my ending code, which i placed in thanks.php
<?php
error_reporting(0);
$to = "info@twpstudio.com";
$subject = "TWP Studio Contact";
$body = $_POST['Name']."\n ".$_POST['email']."\n";
$body.= "\n".$_POST['info'];
if (mail($to, $subject, $body)) {
echo("");
} else {
echo("<p>Message delivery failed...</p>");
}
?>
|
|