Reputation: 213
I am a huge newb when it comes to back-end coding, so I usually just use pre-made contact forms to get things done quickly.....I've tried studying php, but it just confuses me so much....I was a bit embarassed about posting this on here since I didn't write the script myself to begin with, but I have spend the past several days googling, and also looking at other questions on here about contact forms not working, but nothing has worked so far. I have the contact form on my host for testing right here http://www.etdigitaldesign.com/testcontact.html
It gives the "oops! something went wrong!" error, which leads me to believe that the php script isnt working properly. I've tried using different php scripts with this form and nothing is working! I'm guessing something's wrong with the php script? I always check my inbox afterwards incase of false error, but it never sends the email :(
php script here:
<?php
$receiver = "[email protected]"; //PROVIDE YOUR EMAIL ADDRESS
$subject = "Website Contact Form"; //PROVIDE THE SUBJECT OF THE CONTACT FORM MAIL
$name = $_POST['name'];
$email = $_POST['email'];
$mail_message = $_POST['message'];
$message = "<br/>Name: " . $name .
"<br/>Email: " . $email ;
$message .= "<br/>Message: " . $mail_message .
"<br/><br/><br/>Date: " . date("Y-m-d h:i:s");
$siteEmail = $receiver;
$emailTitle = $subject;
$thankYouMessage = "Thank you for contacting us, we'll get back to you shortly.";
$err_msg = 'Please Try Again';
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$headers .='From: ' . $name . ' <' . $email . '>';
if(mail($receiver, $emailTitle, $message, $headers))
{
echo 'success';
}
else
{
echo 'error';
}
?>
I'm also a stackoverflow newb, and I can't seem to get the HTML formatted properly for the message, so i put it on jsbin. you can view it here: http://jsbin.com/wopawulome/edit?html however I have put the contact form by itself in the html document in the first link (www.etdigitaldesign.com/testcontact.html) so that it won't be overwhelming to view the source. its a very short document. If anyone could help I would much appreciate it. I've been trying to get this working for several days now :(
Upvotes: 0
Views: 61
Reputation: 7672
You are not assign value to $receiver
&& $subject
correctly. You are creating INDEX
of array $_POST
there.
Change from
$receiver = $_POST['[email protected]'];
$subject = $_POST['Website Contact Form'];
To
$receiver = "[email protected]";
$subject = "Website Contact Form";
$_POST['website_url']
is not valid index, because you have not defined it in your form anywhere.
Change from
if($_POST['website_url'] == '')
{
if(mail($receiver, $emailTitle, $message, $headers))
{ echo 'success'; }
else { echo 'error'; }
}
else
{
echo 'error';
}
To
if(mail($receiver, $emailTitle, $message, $headers))
{
echo 'success';
}
else
{
echo 'error';
}
Upvotes: 1