Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

Help with PHP mail

New Here ,
Jan 08, 2010 Jan 08, 2010

Hello, I am setting up a simple website for the company I work for and I am having trouble getting the contact form email to work. The following is the code for my feedback.php.

<?php

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

// $mailto - set to the email address you want the form
// sent to, eg
//$mailto          = "youremailaddress@example.com" ;

$mailto = "prepress@bestimageprinters.net" ;

// $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 = "contactus.html" ;
$errorurl = "error.html" ;
$thankyouurl = "thankyou.html" ;

$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( 'Contact Us/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:<br />" .
     "$http_referrer<br />" .
     "------------------------------------------------------------<br />" .
     "<br />Name of sender: $fullname" .
     "<br /><br />Email of sender: $email" .
     "<br /><br />-------------------- COMMENTS --------------------<br /><br />
" .
     $comments .
     "<br /><br />------------------------------------------------------------<br />" ;

$headers =
     "From: \"$fullname\" <$fromemail>" . $headersep . "Reply-To: \"$email\" <$email><br /><br />" . $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 );
}
print("MAILTO<br />");
print($mailto);
print("<br /><br />SUBJECT<br />");
print($subject);
print("<br /><br />MESSAGEPROPER<br />");
print($messageproper);
print("<br /><br />HEADERS<br />");
print($headers);

//header( "Location: $thankyouurl" );
exit ;

?>

The part at the bottom I did to make sure that it was emailing to the right place, and it is. But I never get an email. The site is not live yet so this is all from my computer using the builtin Apache webserver. I am thinking I need to change some configuration in Apache, but I am not sure, nor am I sure how to change the config. in Apache to allow the email to be sent. I have enabled PHP.

TOPICS
Server side applications
458
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jan 08, 2010 Jan 08, 2010

Do you have a mail server install on your computer? That may be the problem. Try uploading files and test on remote site.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
New Here ,
Jan 08, 2010 Jan 08, 2010
LATEST

No I have no mail server on this computer. Our mail server is on our main server, can I point Apache to that? How?

Edit...And can I setup a fake Remote sever...My boss hasn't decided what he wants to do about hosting.

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines