jonathanduane2010
asked on
issue sending mail from website
Hi guys,
I am having an issue with the form on site here at http://www.detergentingredients.com/contact.html
is it maybe something to do with the process.php ?
I am having an issue with the form on site here at http://www.detergentingredients.com/contact.html
is it maybe something to do with the process.php ?
ASKER
ok i have put one in there, but it just hangs on the page
is this correct
<?php
if(isset($_POST['submit'])) {
$to = 'jonathanduane@iradio.ie' ; //put your email address on which you want to receive the information
$subject = 'hello'; //set the subject of email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
<tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
<tr><td>Contact No</td><td>".$_POST['contact']."</td></tr>
<tr><td>Message</td><td>".$_POST['message']."</td>
</tr></table>" ;
mail($to, $subject, $message, $headers);
header('Location: contact.php');
}
?>
is this correct
Not quite.
Your code will only get called if there is a POST key of 'submit':
if(isset($_POST['submit']) ) {
There isn't one in your form. You need to give your submit button a name of 'submit':
<input type='submit' value='Submit Form' name='submit'>
Something else of note, You're creating the message using the following form fields:
name
email
contact
message
But your form actually has these fields:
Name
Email
Company
Telephone
Comments
Your code will only get called if there is a POST key of 'submit':
if(isset($_POST['submit'])
There isn't one in your form. You need to give your submit button a name of 'submit':
<input type='submit' value='Submit Form' name='submit'>
Something else of note, You're creating the message using the following form fields:
name
contact
message
But your form actually has these fields:
Name
Company
Telephone
Comments
ASKER
sorry, i just found that process.php online
how does this look
how does this look
<?php
if(isset($_POST['submit'])) {
$to = 'jonathanduane@iradio.ie' ; //put your email address on which you want to receive the information
$subject = 'hello'; //set the subject of email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<table><tr><td>Your Name</td><td>".$_POST['name']."</td></tr>
<input type='submit' value='Submit Form' name='submit'>
<tr><td>E-Mail</td><td>".$_POST['email']."</td></tr>
<tr><td>Company No</td><td>".$_POST['Company']."</td></tr>
<tr><td>Telephone</td><td>".$_POST['Telephone']."</td>
<tr><td>Comments</td><td>".$_POST['Comments']."</td>
</tr></table>" ;
mail($to, $subject, $message, $headers);
header('Location: contact.php');
}
?>
Is the mail() function working correctly when you isolate it and test it (without using the form)? It returns a value that you can test for success or failure, and you would want to test this in your script and trigger an error or throw an exception if that return value indicated a failure of the function. A good indicator does not guarantee success of the entire email process, but it would eliminate the need to consider one point of failure and that would help us move on to the next things that should be checked.
Important reading here:
http://php.net/manual/en/mail.requirements.php
http://php.net/manual/en/function.mail.php
Important reading here:
http://php.net/manual/en/mail.requirements.php
http://php.net/manual/en/function.mail.php
You seem to have added the submit button in your process.php script. That's not what I meant. You need to update the submit button in your form.
ASKER
ok i have done that, but no change
You've now got 2 submit buttons on your form - you need one one, that includes the name attribute. Your form was fine as it was - you just needed to add name="submit" to it.
Once you've done that, add some simple logging to your PHP script. It'll help you figure out what's going on.
Once you've got that working, you'll really need to extend yout script to check that the POST array actually contains data and that the data contained is exactly what you need.
Once you've done that, add some simple logging to your PHP script. It'll help you figure out what's going on.
<?php
//Turn on error reporting
error_reporting(E_ALL);
ini_set('display_errors', 1);
if(isset($_POST['submit'])) {
$to = 'jonathanduane@iradio.ie' ; //put your email address on which you want to receive the information
$subject = 'hello'; //set the subject of email.
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";
$message = "<table><tr><td>Your Name</td><td>".$_POST['Name']."</td></tr>
<tr><td>E-Mail</td><td>".$_POST['Email']."</td></tr>
<tr><td>Company No</td><td>".$_POST['Company']."</td></tr>
<tr><td>Telephone</td><td>".$_POST['Telephone']."</td>
<tr><td>Comments</td><td>".$_POST['Comments']."</td>
</tr></table>" ;
$mailsent = mail($to, $subject, $message, $headers);
if ($mailsent) {
header('Location: contact.php');
}
else
{
echo "The mail was not sent";
}
} else {
echo "No POST data was found";
}
?>
Once you've got that working, you'll really need to extend yout script to check that the POST array actually contains data and that the data contained is exactly what you need.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Submit your form and you'll get a 404 Page Not Found error /phpform/use/contact_form/