the mail() function
Moderators: macek, egami, gesf
by jjcogar » Thu Apr 21, 2011 12:45 am
I've got the script mailing the data to me, but it is not ending on the correct page/location. Any ideas?
- Code: Select all
<?php /*
$mailto = 'joshuacogar1@gmail.com' ;
$subject = "Online Trip Request" ;
$formurl = "http://www.riverrescue-training/registration.php" ;
$thankyouurl = "http://www.riverrescue-training/registration_thankyou.php" ;
$errorurl = "http://www.riverrescue-training/registration_error.php" ;
$email_is_required = 1;
$name_is_required = 1;
$comments_is_required = 0;
$uself = 0;
$use_envsender = 0;
$use_sendmailfrom = 0;
$smtp_server_win = '' ;
$use_webmaster_email_for_from = 0;
$use_utf8 = 1;
$my_recaptcha_private_key = 'private key' ;
// -------------------- END OF CONFIGURABLE SECTION ---------------
define( 'MAX_LINE_LENGTH', 998 );
$headersep = (!isset( $uself ) || !$uself) ? "\r\n" : "\n" ;
$content_type = (!isset( $use_utf8 ) || ($use_utf8 == 0)) ? 'Content-Type: text/plain; charset="iso-8859-1"' : 'Content-Type: text/plain; charset="utf-8"' ;
if (!isset( $use_envsender )) { $use_envsender = 0 ; }
if (isset( $use_sendmailfrom ) && $use_sendmailfrom) {
ini_set( 'sendmail_from', $mailto );
}
if (isset( $smtp_server_win ) && strlen($smtp_server_win)) {
ini_set( 'SMTP', $smtp_server_win );
}
$envsender = "-f$mailto" ;
$fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;
$email = $_POST['email'] ;
$cell_phone = $_POST['cell_phone'] ;
$available_courses = $_POST['available_courses'] ;
$where_from = $_POST['where_from'] ;
$selected_radio = $_POST['radiogroup1'];
$comments = $_POST['comments'] ;
if (!isset($_POST['submit'])) {// if page is not submitted to itself echo the form
}
$http_referrer = getenv( "HTTP_REFERER" );
if (!isset($_POST['email'])) {
header( "Location: $formurl" );
exit ;
}
if (($email_is_required && (empty($email) || !preg_match('/@/', $email))) || ($name_is_required && empty($fullname)) || ($comments_is_required && empty($comments))) {
header( "Location: $errorurl" );
exit ;
}
if ( preg_match( "/[\r\n]/", $fullname ) || preg_match( "/[\r\n]/", $email ) ) {
header( "Location: $errorurl" );
exit ;
}
if (strlen( $my_recaptcha_private_key )) {
require_once( 'recaptchalib.php' );
$resp = recaptcha_check_answer ( $my_recaptcha_private_key, $_SERVER['REMOTE_ADDR'], $_POST['recaptcha_challenge_field'], $_POST['recaptcha_response_field'] );
if (!$resp->is_valid) {
header( "Location: $errorurl" );
exit ;
}
}
if (empty($email)) {
$email = $mailto ;
}
$fromemail = (!isset( $use_webmaster_email_for_from ) || ($use_webmaster_email_for_from == 0)) ? $email : $mailto ;
if (function_exists( 'get_magic_quotes_gpc' ) && get_magic_quotes_gpc()) {
$comments = stripslashes( $comments );
}
$messageproper =
"This message was sent from:\n" .
"$http_referrer\n" .
"------------------------------------------------------------\n" .
"Name of sender: $fullname\n" .
"Email of sender: $email\n" .
"Cell Phone: $cell_phone\n" .
"Course Date: $available_courses\n" .
"Where From: $where_from\n" .
"Re-cert or Full Registrant: $selected_radio\n" .
"------------------------- COMMENTS -------------------------\n\n" .
wordwrap( $comments, MAX_LINE_LENGTH, "\n", true ) .
"\n\n------------------------------------------------------------\n" ;
$headers =
"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.16.1" .
$headersep . 'MIME-Version: 1.0' . $headersep . $content_type ;
if ($use_envsender) {
mail($mailto, $subject, $messageproper, $headers, $envsender );
}
else {
mail($mailto, $subject, $messageproper, $headers );
}
header( "Location: $thankyouurl" );
exit ;
header( "Location: $thankyouurl" )
?>
-
jjcogar
- New php-forum User

-
- Posts: 4
- Joined: Mon Mar 14, 2011 10:20 am
by egami » Thu Apr 21, 2011 6:12 am
That's because you're missing the TLD in your URL's..
riverrescue-tranning.com?
riverrescue-tranning.net?
you can't have
www.riverrescue-tranning/website.phpIt doesn't know the domain to look for.
-

egami
- php-forum GURU

-
- Posts: 2197
- Joined: Wed Oct 06, 2010 11:19 am
- Location: Happy Valley, UT
by jjcogar » Thu Apr 21, 2011 11:28 pm
Egami,
Thanks for your help! I did correct the problem you found, but unfortunately it didn't fix the problem. When I submit the form, it gives the address to the php script (in the address bar not the page), and a blank white page. Any other ideas?
-
jjcogar
- New php-forum User

-
- Posts: 4
- Joined: Mon Mar 14, 2011 10:20 am
by egami » Fri Apr 22, 2011 5:26 am
set traps on your IF statements, to find out where it's failing.
-

egami
- php-forum GURU

-
- Posts: 2197
- Joined: Wed Oct 06, 2010 11:19 am
- Location: Happy Valley, UT
by johnj » Fri Apr 22, 2011 5:29 am
a).check if the thank you page is present
b). What are you trying to do here?
header( "Location: $thankyouurl" );
exit ;
header( "Location: $thankyouurl" )
header..then an exit and then again a header.
'exit' will stop/terminate the script....after that what is the use of a new header statement...??
-
johnj
- php-forum Super User

-
- Posts: 1470
- Joined: Thu Mar 10, 2011 5:07 pm
by andyrichin » Mon May 02, 2011 7:09 am
I am having problems with a contact form as well. It will not send to my email. Is there any way you could provide your HTML code as well? Would be greatly appreciated.
-
andyrichin
- New php-forum User

-
- Posts: 22
- Joined: Fri Apr 29, 2011 5:02 pm
Return to PHP coding => Mail
Who is online
Users browsing this forum: No registered users and 2 guests