Jump to content

Recommended Posts

Hi guys,

 

This is a script which emails a form to the email address inserted in the script.

Its supposed to check the fields of the forma and then send an email with the info to the email address.

The script checks the form fine and goes to the correct page.

But I dont get the email with the information, so basically, its not sending the email correctly, or I'm not receiving it ?

 

here's the script, lemme know what you guys think.

 

Thanks !

 

<?php

 

// ------------- CONFIGURABLE SECTION ------------------------

 

// $mailto - set to the email address you want the form

// sent to, eg

//$mailto = "youremailaddress@example.com" ;

 

$mailto = '[i've set the email address here without the brackets]' ;

 

// $subject - set to the Subject line of the email, eg

//$subject = "Feedback Form" ;

 

$subject = "Feedback Form" ;

 

// the pages to be displayed, eg

//$formurl = "http://www.example.com/feedback.html" ;

//$errorurl = "http://www.example.com/error.html" ;

//$thankyouurl = "http://www.example.com/thankyou.html" ;

 

$formurl = "[All of these are fine since script goes to correct page after user clicks submit]" ;

$errorurl = "[All of these are fine since script goes to correct page after user clicks submit]" ;

$thankyouurl = "[All of these are fine since script goes to correct page after user clicks submit]" ;

 

$email_is_required = 1;

$name_is_required = 1;

$comments_is_required = 1;

$uself = 0;

$use_envsender = 0;

$use_sendmailfrom = 0;

$use_webmaster_email_for_from = 0;

$use_utf8 = 1;

$my_recaptcha_private_key = '' ;

 

// -------------------- END OF CONFIGURABLE SECTION ---------------

 

$headersep = (!isset( $uself ) || ($uself == 0)) ? "\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 );

}

$envsender = "-f$mailto" ;

$fullname = (isset($_POST['fullname']))? $_POST['fullname'] : $_POST['name'] ;

$email = $_POST['email'] ;

$comments = $_POST['comments'] ;

$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" .

"------------------------- COMMENTS -------------------------\n\n" .

$comments .

"\n\n------------------------------------------------------------\n" ;

 

$headers =

"From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$fullname\" <$email>" . $headersep . "X-Mailer: chfeedback.php 2.15.0" .

$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 ;

 

?>

 

Link to comment
https://forums.phpfreaks.com/topic/202102-form-email-script/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.