I utilized a client’s contact form email for their website since my standard one didn’t work on her site. Now, she’s receiving a few form submissions, such as mine and a random, but when I submit using my personal email or she from hers, she’s not receiving the contact form email at all.
What’s wrong with this code that it’s not sending? Happy to provide whatever additional code you need (e.g. the form).
The PHP script (mail.php)
function stripFormSlashes($arr)
{
if(!is_array($arr))
{
return stripslashes($arr);
}
else
{
return array_map('stripFormSlashes', $arr);
}
}
if(get_magic_quotes_gpc())
{
$_POST = stripFormSlashes($_POST);
}
$message = "";
$message .= "First Name: " . htmlspecialchars($_POST['first_name'], ENT_QUOTES) . "<br >n";
$message .= "Last Name: " . htmlspecialchars($_POST['last_name'], ENT_QUOTES) . "<br >n";
$message .= "Email: " . htmlspecialchars($_POST['email'], ENT_QUOTES) . "<br >n";
$message .= "Phone: " . htmlspecialchars($_POST['telephone'], ENT_QUOTES) . "<br >n";
$message .= "Company: " . htmlspecialchars($_POST['company'], ENT_QUOTES) . "<br >n";
$message .= "Comments: " . htmlspecialchars($_POST['message'], ENT_QUOTES) . "<br >n";
$lowmsg = strtolower($message);
$injection_strings = array ( "content-type:","charset=","mime-version:","multipart/mixed","bcc:","cc:");
foreach($injection_strings as $suspect)
{
if((stristr($lowmsg, $suspect)) || (stristr(strtolower($_POST['first_name']), $suspect)) || (stristr(strtolower($_POST['email']), $suspect)))
{
die ( 'Illegal Input. Go back and try again. Your message has not been sent.' );
}
}
$headers = "MIME-Version: 1.0rnContent-type: text/html; charset=utf-8rn";
$headers .= "Content-Transfer-Encoding: 8bitrn";
$headers .= "From: "" . $_POST['first_name'] . " " . $_POST['last_name'] . "" <" . $_POST['email'] . ">rn";
$headers .= "Reply-To: " . $_POST['email'] . "rn";
mail("[email protected]", "Contact Form Submission", $message, $headers);
header("Location: ../thank_you.html");
?>
The form modal
<div
class="modal fade"
id="contactForm"
data-bs-backdrop="static"
data-bs-keyboard="false"
tabindex="-1"
aria-labelledby="contactFormLabel"
aria-hidden="true"
>
<div class="modal-dialog modal-lg">
<div class="modal-content">
<div
class="modal-header border-0"
style="background-color: var(--tp-theme-main-bg)"
>
<h2
class="modal-title fs-5"
id="ContactFormLabel"
style="font-size: 36px !important"
>
Contact Me!
</h2>
<button
type="button"
class="btn-close"
data-bs-dismiss="modal"
aria-label="Close"
></button>
</div>
<div class="modal-body form-group col-12 px-5">
<p>
contact text
</p>
<form
action="./assets/mail.php"
method="POST"
id="contactForm"
>
<div class="row g-3">
<div class="col-md-6">
<div class="input-item">
<input
type="text"
name="first_name"
placeholder="First Name"
required
/>
</div>
</div>
<div class="col-md-6">
<div class="input-item">
<input
type="text"
name="last_name"
placeholder="Last Name"
required
/>
</div>
</div>
<div class="col-lg-12">
<div class="input-item">
<input
type="text"
name="company"
placeholder="Company Name"
/>
</div>
</div>
<div class="col-md-6">
<div class="input-item">
<input
type="text"
name="email"
placeholder="Email Address"
required
/>
</div>
</div>
<div class="col-md-6">
<div class="input-item">
<input
type="tel"
name="telephone"
placeholder="(555) 123-4567"
/>
</div>
</div>
<div class="col-12">
<div class="input-item-textarea">
<textarea
name="message"
placeholder="Let us know what you're looking for"
required
></textarea>
</div>
</div>
</div>
<div class="modal-footer border-0 me-auto flex-row-reverse flex-md-row">
<button
type="button"
class="btn btn-secondary"
data-bs-dismiss="modal"
>
Close
</button>
<button
type="submit"
name="submit"
class="btn btn-primary"
style="position: relative"
>
Submit
</button>
</div>
</form>
</div>
</div>
</div>
</div>
I’ve tried to change the FROM around a bit to see if maybe that was causing issues, but that seems to just kill the submissions completely.
Randy Christenhusz is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.