Trying to get my PHP to generate emails

I have a form on my website that calls a PHP script hosted on another website. The script is supposed to generate two emails - one to me to alert that the form has been filled out, and one to the user as a confirmation email. This script used to work fine, but since switching hosts and enabling SSL, it now just redirects me to a blank page with the PHP file in the address bar with ?i=1 after it instead of generating the emails and redirecting me to the “thank you” page. This script is kind of old and might be outdated - I don’t have a ton of experience with PHP and my entire site is reverse engineered and jerry rigged. But if anyone can help figure out where the problem is, I will be eternally grateful.

if(isset($_POST['email'])) {
     
    // CHANGE THE TWO LINES BELOW
    $email_to = "[email protected]";
    $email_toa = "[email protected]";
     
    $email_subject = "Kami-Con HAI 2024 - AMV Submission";
    $conf_subject = "Kami-Con HAI 2024 - AMV Contest Confirmation"; 
     
    function died($error) {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error."<br /><br />";
        echo "Please click BACK in your browser and fix these errors.<br /><br />";
        die();
    }
     
    // validation expected data exists
    if(!isset($_POST['handle']) ||
        !isset($_POST['amv_category']) ||
        !isset($_POST['youtube'])) {
        died('We are sorry, but there appears to be a problem with the form you submitted.');       
    }

if(!empty($_POST['first_name'])) {}
else{
died('First name is required.');
}
if(!empty($_POST['last_name'])) {}
else{
died('Last name is required.');
}
if(!empty($_POST['amv_title'])) {}
else{
died('Title of AMV is required.');
}
if(!empty($_POST['amv_song'])) {}
else{
died('Song Used is required.');
}
if(!empty($_POST['amv_artist'])) {}
else{
died('Song Artist is required.');
}
if(!empty($_POST['amv_anime'])) {}
else{
died('Animation sources are required.');
}
if(!empty($_POST['amv_link'])) {}
else{
died('AMV link is required.');
}
if(!empty($_POST['attending'])) {}
else{
died('Are you attending the convention?  This answer is required.');
}
if(!empty($_POST['email'])) {}
else{
died('Email address is required.');
}

if(!isset($_POST['consent'])) {
died('You must check that you have read and understand the AMV League Rules and Criteria to submit a video.');
}

function IsChecked($chkname,$value)
    {
        if(!empty($_POST[$chkname]))
        {
            foreach($_POST[$chkname] as $chkval)
            {
                if($chkval == $value)
                {
                    return true;
                }
            }
        }
        return false;
    }
    $first_name = $_POST['first_name']; // required
    $last_name = $_POST['last_name']; // required
    $handle = $_POST['handle']; // not required
    $amv_title = $_POST['amv_title']; // required
    $amv_category = $_POST['amv_category']; // required
    $amv_song = $_POST['amv_song']; // required
    $amv_artist = $_POST['amv_artist']; // required
    $amv_anime = $_POST['amv_anime']; // required
    $amv_link = $_POST['amv_link']; // required
    $email_from = $_POST['email']; // required    
    $attending = $_POST['attending']; // required
    $youtube = $_POST['youtube']; // not required
    $consent = $_POST['consent']; // required
     
    $error_message = "";
    $email_exp = '/^[A-Za-z0-9._%-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}$/';
  if(!preg_match($email_exp,$email_from)) {
    $error_message .= 'The Email Address you entered does not appear to be valid.<br />';
  }
    $string_exp = "/^[A-Za-z' .-]+$/";
  if(!preg_match($string_exp,$first_name)) {
    $error_message .= 'The First Name you entered does not appear to be valid.<br />';
  }
  if(!preg_match($string_exp,$last_name)) {
    $error_message .= 'The Last Name you entered does not appear to be valid.<br />';
  }
    if(strlen($error_message) > 0) {
    died($error_message);
  }
    $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 .= "Name: ".clean_string($first_name)." ".clean_string($last_name)."\n";
    $email_message .= "Handle: ".clean_string($handle)."\n";
    $email_message .= "Email: ".clean_string($email_from)."\n";
    $email_message .= "Title of AMV: ".clean_string($amv_title)."\n";    
$email_message .= "Category: ".clean_string($amv_category)."\n";
$email_message .= "Song: ".clean_string($amv_song)." by ".clean_string($amv_artist)."\n";
$email_message .= "Anime Used: ".clean_string($amv_anime)."\n\n";
$email_message .= "Youtube: ".clean_string($youtube)."\n\n";
$email_message .= clean_string($amv_link)."\n\n\n"; 

$amv_category = strtoupper($amv_category);
$email_message .= clean_string($amv_category)."\n";
$email_message .= clean_string($amv_title)."\n";
$email_message .= "\"".clean_string($amv_song)."\""."\n";
$email_message .= clean_string($amv_artist)."\n";
$email_message .= clean_string($amv_anime)."\n";
$email_message .= "Editor: ".clean_string($handle)."\n\n";

$email_message .= "Attending? ".clean_string($attending)."\n\n";

$email_message .= "Full Name: ".clean_string($first_name)." ".clean_string($last_name)."\n";    
$email_message .= "Email: ".clean_string($email_from)."\n\n";

$email_message .= "Download: ".clean_string($amv_link)."\n";  
$email_message .= "Streaming: ".clean_string($youtube)."\n\n";  





$conf_message .="Thank you for your interest.  We have received the following submission from you: \n\n";
$amv_category = strtoupper($amv_category);
$conf_message .= clean_string($amv_category)."\n";
$conf_message .= clean_string($amv_title)."\n";
$conf_message .= "\"".clean_string($amv_song)."\""."\n";
$conf_message .= clean_string($amv_artist)."\n";
$conf_message .= clean_string($amv_anime)."\n";
$conf_message .= "Editor: ".clean_string($handle)."\n\n";


$conf_message .= "Full Name: ".clean_string($first_name)." ".clean_string($last_name)."\n";    
$conf_message .= "Email: ".clean_string($email_from)."\n\n";

$conf_message .= "Download: ".clean_string($amv_link)."\n";  
$conf_message .= "Streaming: ".clean_string($youtube)."\n\n";
$conf_message .= "We will review this submission at our earliest convenience and contact you if there are any further issues.\n\n";
$conf_message .= "Regards,\n";
$conf_message .= "Annie Bowyer\n";
$conf_message .= "Vitamin H Productions\n";  



$conf_headers = 'From: '.$email_toa."\r\n".
'Reply-To: '.$email_toa."\r\n" .
'X-Mailer: PHP/' . phpversion();
// create email headers
$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
mail($email_to, $email_subject, $email_message, $headers);  
mail($email_from, $conf_subject, $conf_message, $conf_headers); 

 header( 'Location: http://vitaminh.weebly.com/thankyou.html' ) ; 

}
die();
?>
type or paste code here

Since there’s nothing in the code that does that, this is either from the form’s action attribute or there’s some URL rewriting or a redirect on the server that’s adding it.

Does the form’s action attribute use https for the URL? Can you share the code for the form, with the actual action attribute? Is there any URL rewriting in a .htaccess file? Is there a redirect from non-http URLs to https URLs?

What does temporarily adding the following, immediately after the first opening <?php tag, show -

ini_set('display_errors', '1');
error_reporting(-1);
echo '<pre>'; print_r($_POST); echo '</pre>';

Here is the code for the form:

<form enctype="multipart/form-data" action="https://vitamin-h.com/formSubmit_kamihai2024.php" method="POST" id="form-130003657957698085">
<div id="130003657957698085-form-parent" class="wsite-form-container" style="margin-top:10px;">
  <ul class="formlist" id="130003657957698085-form-list">
 

<div><div class="wsite-form-field wsite-name-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="input-434265739796273795">Real Name <span class="form-required">*</span></label>
				<div style="clear:both;"></div>
				<div class="wsite-form-input-container wsite-form-left wsite-form-input-first-name">
					<input id="input-434265739796273795" class="wsite-form-input wsite-input" type="text" name="first_name" />
					<label class="wsite-form-sublabel" for="first_name">First</label>
				</div>
				<div class="wsite-form-input-container wsite-form-right wsite-form-input-last-name">
					<input id="input-434265739796273795-1" class="wsite-form-input wsite-input" type="text" name="last_name" />
					<label class="wsite-form-sublabel" for="last_name">Last</label>
				</div>
				<div id="instructions-434265739796273795" class="wsite-form-instructions" style="display:none;"></div>
			</div>
			<div style="clear:both;"></div></div>
<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="handle">Name you would like the video credited to (Optional)<span class="form-required"></span></label>
				<div class="wsite-form-input-container">
					<input id="input-413078534950562730" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="handle" />
				</div>
				<div id="instructions-413078534950562730" class="wsite-form-instructions" style="display:none;"></div>
			</div></div>



<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="amv_title">Title of AMV <span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<input id="input-413078534950562730" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="amv_title" />
				</div>
				<div id="instructions-413078534950562730" class="wsite-form-instructions" style="display:none;"></div>
			</div></div>


<div><div class="wsite-form-field" style="margin:5px 0px 0px 0px;">
  <label class="wsite-form-label" for="amv_category">Select Category<span class="form-required">*</span></label>
  <div class="wsite-form-radio-container">
    <select name='amv_category' class='form-select'>
	<option value='Action'>Action</option>
	<option value='Drama'>Drama</option>
	<option value='Fun/Upbeat'>Fun/Upbeat</option>
</select>
<label class="wsite-form-sublabel" for="amv_category"></label>
  </div>
  <div id="instructions-Select Category" class="wsite-form-instructions" style="display:none;"></div>
</div></div>

<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="amv_song">Song Used <span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<input id="input-413078534950562730" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="amv_song" />
				</div>
				<div id="instructions-413078534950562730" class="wsite-form-instructions" style="display:none;"></div>
			</div></div>



<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="amv_artist">Song Artist <span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<input id="input-413078534950562730" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="amv_artist" />
				</div>
				<div id="instructions-413078534950562730" class="wsite-form-instructions" style="display:none;"></div><i>For Trailers, list the distributor of the film (such as Warner Bros. Pictures or 20th Century Fox).</i>
			</div></div>

<br>


<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="amv_anime">List All Animation Sources (e.g. "<i>Black Butler, My Hero Academia.</i>") <span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<textarea id="input-156461601796647716" class="wsite-form-input wsite-input wsite-input-width-370px" name="amv_anime" style="height: 200px"></textarea>
				</div>
				<div id="instructions-156461601796647716" class="wsite-form-instructions" style="display:none;"></div>Please use English titles, if available.
			</div></div>

<br>

<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="amv_link">Link to download AMV (MUST be hosted by a site such as Dropbox or Google Drive!)<span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<input id="input-413078534950562730" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="amv_link" />
				</div>
				</div>


<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="email">Email <span class="form-required">*</span></label>
				<div class="wsite-form-input-container">
					<input id="input-592136910879563521" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="email" />
				</div>
				<div id="instructions-592136910879563521" class="wsite-form-instructions" style="display:none;"></div>
			</div></div>

<br>

<div><div class="wsite-form-field" style="margin:5px 0px 5px 0px;">
				<label class="wsite-form-label" for="youtube">Is your video on a streaming site such as YouTube, Vimeo, Google Drive, etc? If so, give us the video link here. (Optional)<span class="form-required"></span></label>
				<div class="wsite-form-input-container">
					<input id="input-592136910879563521" class="wsite-form-input wsite-input wsite-input-width-370px" type="text" name="youtube" />
				</div>
				<div><div id="instructions-Select Category" class="wsite-form-instructions" style="display:none;"></div>
<b>(Note: This does NOT count as your video entry!  This is just so we can link to your video in the contest results.)</b>
</div></div>

<br>

<div><div class="wsite-form-field" style="margin:5px 0px 0px 0px;">
  <label class="wsite-form-label" for="attending">Are you planning to attend Kami-Con HAI?<span class="form-required">*</span></label>
  <div class="wsite-form-radio-container">
    <select name='attending' class='form-select'>
	<option value='No'>No</option>
	<option value='Yes'>Yes</option>
</select>
<label class="wsite-form-sublabel" for="amv_category"></label>
  </div>
  <div id="instructions-Select Category" class="wsite-form-instructions" style="display:none;"></div>
</div></div>

</div>
<br>

<div><div class="wsite-form-field" style="margin:5px 0px 0px 0px;">
  <label class="wsite-form-label" for="consent">I have read and understand the Rules and Criteria</a>. <span class="form-required">*</span></label>
  <div class="wsite-form-radio-container">
    <span class='form-radio-container'><input type='checkbox' id='checkbox-0-_u248052609560376621' name='consent' value='1' /><label for='checkbox-0-_u248052609560376621'>Yes</label></span>

  </div>
  <div id="instructions-I have read and understand the Rules and Criteria." class="wsite-form-instructions" style="display:none;"></div>
</div></div>
  </ul>
</div>
<div style="display:none; visibility:hidden;">
  <input type="text" name="wsite_subject" />
</div>
<div style="display:none; visibility:hidden;">
  <input type="text" name="wsite_subject" />
</div>
<br>
<div style="text-align:left; margin-top:10px; margin-bottom:10px;">
  <input type="hidden" name="form_version" value="2" />
  <input type="hidden" name="wsite_approved" id="wsite-approved" value="approved" />
  <input type="hidden" name="ucfid" value="119254649727518047" />
  <input type="submit" style='position:absolute;top:0;left:-9999px;width:1px;height:1px' /><a class='wsite-button' onclick="document.getElementById('form-130003657957698085').submit()"><span class='wsite-button-inner'>Submit</span></a>

</div></font>
</div>
</form>


</div></div>
</div>
			</div>
			

Added that code after the first PHP tag, and now the page is no longer blank, it says:

Array
(
)

Since there’s no post data, the conditional statement in the php code is false and none of the main php code is being executed.

The action attribute is not the cause. That leaves the rest of what I wrote as a possible cause -

The problem is on the server in how the php script is getting invoked when the form submits a post request to the server. You will likely need to involve the web hosting support to solve this.

Sponsor our Newsletter | Privacy Policy | Terms of Service