Email form problem

To PHPHelp Forumgoers,

My PHP email form is not sending to the address I specified, and I think it’s because I added in an if-else statement to check for input of a valid email address. I’ve put the HTML and PHP scripts online and filled the live form out with several valid email addresses, with no success. I tried changing the recipient’s email, too, with no success. Am I missing a glaring error in my code, or maybe things are just not in the right order?

Any help would be SUPER appreciated. Thank you so much. :slight_smile:

The code (in external PHP file “order.php”) :
[php]<?php
$to = "[email protected]";
$subject = “Custom Order Message”;
$email = $_REQUEST[‘email’] ;
$message = $_REQUEST[‘message’] ;
$from = $_REQUEST[‘name’];
$budget = $_REQUEST[‘budget’];
$colors[] = $_REQUEST[‘colors[]’];

$headers = “From: $email”;
$sent = mail($to, $from, $subject, $message, $budget, $headers) ;

if( !eregi("^[a-z0-9]+([_\.-][a-z0-9]+)". "@([a-z0-9]+([.-][a-z0-9]+))$",$email)) {
header( ‘Location: order/invalidemail.html’ ) ;
}else{
header( ‘Location: order/messagesent.html’ ) ;
}
if($sent)
{print “Your custom order query was sent successfully.”; }
else
{print “An error occured while sending your custom order query. Please try again.”; }
?>[/php]

  • Martha

There were quite a few errors in your code.

See the comments in the code for details.

[php]

<?php $email = $_REQUEST['email']; $senderMessage = $_REQUEST['message']; //renamed so as not to be confused with the $message variable used in the mail function $name = $_REQUEST['name']; //renamed name so as to not be confused with from perhaps being an eMail address $budget = $_REQUEST['budget']; for($i=0;$i<count($_REQUEST['colors']);$i++) { //you had incorrectly programmed the colors array $colors[$i] = $_REQUEST['colors'][$i]; //this creates a new array to hold the array passed by the contact form } //also, you never sent the colors information in your original code, so you would have never received it if(!eregi("^[a-z0-9]+([_\\.-][a-z0-9]+)*". "@([a-z0-9]+([\.-][a-z0-9]+))*$",$email)) { header('Location: order/invalidemail.html'); } //else statement removed, as you had it setup, if the eMail address was valid, it would then be passed to the else statment, where the header command would redirect the user //also, this must be placed earlier in the code, otherwise, it would never check the eMail address until the mail had already been processed $colorList = ''; //blank list to be added on to $excess = ', '; //extra text that will be added below that should not be sent in the finished eMail for($j=0;$j

[/php]

Hope this helps!

Robert

Sponsor our Newsletter | Privacy Policy | Terms of Service