简体   繁体   中英

Contact.php Form Issue

Having trouble with my contact.php form. It seems to be working intermittently and can't spot what I am doing wrong.

Hosting is with GoDaddy and they said to add the following but not sure where relay-hosting.secureserver.net

Any help or references to building one of these would be very helpful. Current code is below.

<?php
 if(isset($_POST['email'])) {

// EDIT THE 2 LINES BELOW AS REQUIRED
$email_to = "info@resonatebusiness.com";
$email_subject = "NEW WEBSITE INQUIRY";


$email_message = "Form details below.\n\n";

function clean_string($string) {
  $bad = array("content-type","bcc:","to:","cc:","href");
  return str_replace($bad,"",$string);
}

$email_message .= "First Name: ".clean_string($full_name)."\n";
$email_message .= "Last Name: ".clean_string($email)."\n";
$email_message .= "Email: ".clean_string($email)."\n";
$email_message .= "Telephone: ".clean_string($subject)."\n";
$email_message .= "Comments: ".clean_string($message)."\n";


$headers = 'From: '.$email_from."\r\n".
 'Reply-To: '.$email_from."\r\n" .
  'X-Mailer: PHP/' . phpversion();
  @mail($email_to, $email_subject, $email_message, $headers);  
  header("Location: http://www.publishingpush.com");
  exit;
  ?>

You are redirecting your form before the mail is sent. Redirect only after successful mail function execution.

if( mail($email_to, $email_subject, $email_message, $headers) ){
 //redirect
}

try the below code and see first if the server is properly trapping the information and sending it to your e-mail -

ps change the location of your thankyou.html redirect page to whatever is your redirect landing page post form submit. If this works , just tweak the php to filter and pre-qualify the information you need.

<?php
/* Set e-mail recipient */
$myemail  = 'info@resonatebusiness.com'; 

/* Check all form inputs using check_input function */
$name = check_input($_POST['full_name']);
$lname = check_input($_POST['last_name']);
$email = check_input($_POST['email']);
$subject = check_input($_POST['subject']);
$spec_message = check_input($_POST['message']); 


/*E-mail Subject */
$subject = 'NEW WEBSITE INQUIRY' ;

/*From Address */
$headers = "From: $name $lname";

/* Let's prepare the message for the e-mail */
$message = "
Name: $name, $lname
E-mail: $email
Subject: $subject
Message: $spec_message
" ;

/* Send the message using mail() function */
mail($myemail, $subject, $message, $headers);

/* Redirect visitor to the thank you page */
header('Location: thankyou.html');
exit();

?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM