Hello, and thank you for creating a forum which will help people like me solve problems. I have tried so many help sites and have tried so many options but am a loss. I have looked at answers to forum questions but still to no avail.
Basically, I have created a page with a form. I made the page in Dreamweaver so the form already includes ‘required’ fields etc. which seem to work fine (but please let me know if any of my code in the form could be causing an issue/is not compatible).
I wish for the form to be submitted and an email with its contents sent to my email. I have therefore created a php script which is linked to in the form action.
The problem is it does not work in most browsers, and although it sends me to the php action page, it tells me “Sorry, there was a problem sending your message.”.
Saying that, it works in my version of Microsoft Edge on my laptop (but not in another version on my home’s desktop).
I will get the success message and I also receive an email.
I am attaching the code for the form and for the php mail() script if you don’t mind and would very much appreciate it if anyone can see why it isn’t working in most instances.
Please note that although I set up the contactus page with the form on it as an html first, I have since saved it as php but have tried both with the same results so this doesn’t seem to make a difference.
Please also note that I have put generic emails in but I have used real ones in my test pages of course.
So the form is as follows:
<form action="newtestacknowledge.php" method="post" enctype="text/plain" id="ContactForm">
<p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-weight: 300; font-size: large;">
<label for="Name">*Name:</label>
<input name="Name" type="text" required="required" id="Name" form="ContactForm" size="50" maxlength="80">
<label for="email"><br>
<br>
*Email:</label>
<input name="Email" type="email" required="required" id="email" form="ContactForm" size="40" maxlength="60">
<label for="tel"><br>
<br>
Phone:</label>
<input name="Phone" type="tel" id="tel" form="ContactForm" size="30">
</p>
<p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
<label for="timezone">Time Zone:</label>
<select name="timezone" id="timezone" form="ContactForm">
<option>Eastern</option>
<option>Central</option>
<option>Mountain</option>
<option>Pacific</option>
<option>Alaska</option>
<option>Hawaii</option>
<option>Other</option>
</select></p>
<p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
<label for="callafter">Best Time to Call: </label>
<select name="callafter" id="callafter" form="ContactForm">
<option value="00:00">12.00 AM</option>
<option value="01:00">01.00 AM</option>
<option value="02:00">02.00 AM</option>
<option value="03:00">03.00 AM</option>
<option value="04:00">04.00 AM</option>
<option value="05:00">05.00 AM</option>
<option value="06:00">06.00 AM</option>
<option value="07:00">07.00 AM</option>
<option value="08:00">08.00 AM</option>
<option value="09:00" selected="">09.00 AM</option>
<option value="10:00">10.00 AM</option>
<option value="11:00">11.00 AM</option>
<option value="12:00">12.00 PM</option>
<option value="13:00">01.00 PM</option>
<option value="14:00">02.00 PM</option>
<option value="15:00">03.00 PM</option>
<option value="16:00">04.00 PM</option>
<option value="17:00">05.00 PM</option>
<option value="18:00">06.00 PM</option>
<option value="19:00">07.00 PM</option>
<option value="20:00">08.00 PM</option>
<option value="21:00">09.00 PM</option>
<option value="22:00">10.00 PM</option>
<option value="23:00">11.00 PM</option>
</select>
<label for="callbefore">to</label>
<select name="callbefore" id="callbefore" form="ContactForm">
<option value="01:00">01.00 AM</option>
<option value="02:00">02.00 AM</option>
<option value="03:00">03.00 AM</option>
<option value="04:00">04.00 AM</option>
<option value="05:00">05.00 AM</option>
<option value="06:00">06.00 AM</option>
<option value="07:00">07.00 AM</option>
<option value="08:00">08.00 AM</option>
<option value="09:00">09.00 AM</option>
<option value="10:00">10.00 AM</option>
<option value="11:00">11.00 AM</option>
<option value="12:00">12.00 PM</option>
<option value="13:00">01.00 PM</option>
<option value="14:00">02.00 PM</option>
<option value="15:00">03.00 PM</option>
<option value="16:00">04.00 PM</option>
<option value="17:00">05.00 PM</option>
<option value="18:00">06.00 PM</option>
<option value="19:00">07.00 PM</option>
<option value="20:00" selected="">08.00 PM</option>
<option value="21:00">09.00 PM</option>
<option value="22:00">10.00 PM</option>
<option value="23:00">11.00 PM</option>
<option value="00:00">12:00 AM</option>
</select>
</p>
<p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: normal; font-weight: 300; font-size: large;">
<label for="Comments">*Comments/Questions:<br>
</label>
<textarea name="Comments" cols="55" rows="6" required="required" id="Comments" form="ContactForm"></textarea>
<br>
</p>
<p style="font-family: Gotham, 'Helvetica Neue', Helvetica, Arial, sans-serif; font-style: oblique; font-weight: 300; font-size: medium;">*required</p>
<p>
<input name="reset" type="reset" id="reset" form="ContactForm" value="reset">
<input name="submit" type="submit" id="submit" form="ContactForm" formenctype="text/plain" value="submit">
</p>
</form>
Here is the php action file in its entirety:
<?php
if(isset($_POST['submit'])) {
$to = ' "My Name" <[email protected]>';
$visitor_email = $_POST['Email'];
$subject = 'New Submission from SYHTS Contact Form';
$message = 'Name: '. $_POST['Name'] . "\r\n\r\n";
$message .= 'Email: '. $_POST['Email'] . "\r\n\r\n";
$message .= 'Phone: '. $_POST['Phone'] . "\r\n\r\n";
$message .= 'Time Zone: '. $_POST['timezone'] . "\r\n\r\n";
$message .= 'Call After: '. $_POST['callafter'] . "\r\n\r\n";
$message .= 'but Before: '. $_POST['callbefore'] . "\r\n\r\n";
$message .= 'Comments: '. $_POST['Comments'];
$headers = "From: [email protected] \r\n";
$headers .="Reply-To: $visitor_email \r\n";
$headers .= 'Content-Type: text/plain; charset=utf-8';
$success = mail($to, $subject, $message, $headers, '[email protected]');
}
function IsInjected($str)
{
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str))
{
return true;
}
else
{
return false;
}
}
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>
<body>
<?php if (isset($success) && $success) { ?>
<h1>Thank you</h1> Your message has been sent.
<?php } else { ?>
Sorry, there was a problem sending your message.
<?php } ?>
</body>
</html>
I have tried so many different alternatives but each time it either doesn’t make a difference or causes a complete fail such as a 404 error.
I should add that one solution was to add the ‘[email protected]’ in the mail() but it makes no difference either way.
I do wonder whether I need another header such as ‘X-Mailer: PHP/’
Thank you for any help that you may be able to offer.