Help - email form/script
Posted: Fri Dec 04, 2009 12:06 pm
I have got a form that uses PHP to send an email to a 'contact us' address. However, it doesn't always work. The majority of the time, it works perfectly, but when one specific form element (a multi-select box) has anything selected in it, it returns the following error:
Line 50 is:
This is the full code:
Any ideas?
and does not send the email. The element that causes the problem (on line 43) is:Warning: implode() [function.implode]: Invalid arguments passed in /home/dysaili1/public_html/train.php on line 43
Warning: Cannot modify header information - headers already sent by (output started at /home/dysaili1/public_html/train.php:43) in /home/dysaili1/public_html/train.php on line 50
Code: Select all
( empty( $data['help'] )?" -not selected -": implode( "," , $data['help'] ) )Code: Select all
header( "Location: " . $_SERVER["PHP_SELF"] . "?thankyou" );This is the full code:
Code: Select all
<?php
function htmlhead()
{
?>
<html>
<head>
<title>Registration Sent</title>
</head>
<body>
<?php
}
function foot()
{
?>
<form method="LINK" action="index.htm"><input type="submit" value="Return to home page"></form>
</body>
</html><?php
}
if ( !empty( $_POST ) ) {
$to = "training@dysailing.com";
$subject = "DYS Training Event Registraion";
function stripandfilterhtml( $string )
{
if ( empty( $string ) )
return " -empty- ";
if ( is_array( $string ) )
$string = array_map( "stripandfilterhtml" , $string );
else
$string = htmlspecialchars( strip_tags( $string ) ) ;
return $string;
}
$data = array_map( "stripandfilterhtml" , $_POST );
$email = $data['email'] ;
$message = "Competitor Info: <br>Helm Name:" . $data['helmname'] . "<br>Email:" . $data['email'] . "<br>Club:" . $data['club'] . "<br>Boat Class:" . $data['class'] . "<br>Sail Number:" . $data['sailno'] . "<br>Event: " . $data['event'] . "<br><br>Parents Info:<br>Name:" . $data['name'] . "<br>Can Help With:" . ( empty( $data['help'] )?" -not selected -": implode( "," , $data['help'] ) ) . "<br>Contact Number:" . $data['telno'] . " <br>Email Address: " . $data['helperemail'];
$headers = "From: $email";
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$sent = mail( $to, $subject, $message, $headers ) ;
if ( $sent ) {
header( "Location: " . $_SERVER["PHP_SELF"] . "?thankyou" );
} else {
header( "Location: " . $_SERVER["PHP_SELF"] . "?email_failed" );
}
}
htmlhead();
if ( isset( $_GET["thankyou"] ) ) {
?>Registration Received<?php
}
if ( isset( $_GET["email_failed"] ) ) {
?>There has been an issue with your registration, please try again. If the problem persists, please inform us through the contact webmaster link on the home page.<?php
}
foot();
?>