Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
does not receive all enquiries from php form using mail() on 1and1 host
Old 07-28-2008, 04:15 AM does not receive all enquiries from php form using mail() on 1and1 host
Average Talker

Posts: 27
Trades: 0
Hi all,

I have a site for someone which uses a contact form to send enquiries via the mail() function with php and it is on a 1and1 shared host.

She says she receieves some mail frmo it but not others.

The form part of the contact page is this:

<form action="handleform.php" method="post" name="contact" onSubmit="MM_validateForm('contact_email','','RisE mail');return document.MM_returnValue">
<table>
<tr>
<td id="leftcol">Name:</td>
<td><input name="contact_name" type="text" size="30"></td>
</tr>
<tr>
<td id="leftcol">Email:</td>
<td><input name="contact_email" type="text" size="30"></td>
</tr>
<tr>
<td id="leftcol">Telephone:</td>
<td><input name="contact_telephone" type="text" size="30"></td>
</tr>
<tr>
<td id="leftcol">Enquiry:</td>
<td><textarea name="contact_enquiry" cols="30" rows="5"></textarea></td>
</tr>
<tr>
<td id="leftcol">&nbsp;</td>
<td><input name="submit" type="submit" value="Submit"> <input name="reset" type="reset" id="reset" value="Reset"></td>
</tr>
</table>
</form>

and the php sections on handleform.php are:

<?php
// Creates fields from form data
$contact_name=$_POST['contact_name'];
$contact_email=$_POST['contact_email'];
$contact_telephone=$_POST['contact_telephone'];
$contact_enquiry=$_POST['contact_enquiry'];

// Creates email fields
$toaddress = 'xxx@xxx.com';
$subject = 'Website enquiry from website';
$mailcontent = 'Name: '.$contact_name."\n"
.'Email: '.$contact_email."\n"
.'Telephone: '.$contact_telephone."\n"
.'Enquiry: '.$contact_enquiry;
$fromaddress = 'From: '.$contact_email;

// Sends email
mail($toaddress, $subject, $mailcontent, $fromaddress);
?>

It appears that she does not receive every enquiry from customers that comes through the site form. Some enquiries come through and others don't. I have asked her to check her email spam folder and they are not going into that which makes me wonder if there is a problem with the form/host setup.

I also use the same code for forms on other websites that use 1and1 shared hosting and they seem to work fine (or at least I've had no reports or problems).

I just wondered if anyone has any ideas to this? Whether it is anything in that code, or if it is maybe a problem being on 1and1 shared hosting (which has the mail enabled working in phpinfo), or it could be the fact that the onSubmit action in the form (which uses the validate form behaviour in Dreamweaver) is having an effect? Or if anyone has any other ideas to try to make the mail submit better (I know mail() on its own is not always the best!)?

Many thanks
gavrd1 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-28-2008, 07:20 AM Re: does not receive all enquiries from php form using mail() on 1and1 host
digitalfusion's Avatar
Skilled Talker

Posts: 73
Name: Martin
Location: Fife, Scotland
Trades: 0
Hi there,

I can't spot any obvious mistakes in your coding, but i always use this piece of code for contact forms and it's never let me down (It's also got a error checking piece on it to check if the mail() function returned true or false), This is not always an indication of email sent or not but its telling you theres nothing wrong with your mail() function, which would mean error at the mail server either the senders or yours.

I also tend to like using $_REQUEST instead of $_POST or $_GET because it's usually much more reliable at finding the posted information.

PHP Code:
<?php
// Creates fields from form data    
    
$contact_name=$_REQUEST['contact_name'];
    
$contact_email=$_REQUEST['contact_email'];
    
$contact_telephone=$_REQUEST['contact_telephone'];
    
$contact_enquiry=$_REQUEST['contact_enquiry'];

    
//Send Email to form owner
$pfw_header "From: $contact_email\n"
  
"Reply-To: $contact_email\n";
$pfw_subject "Website Enquiry\n";
$pfw_email_to "xxx@xxx.com\n";
$pfw_message "Name: $contact_name\n"
                    
."Email: $contact_email \n"
                    
."Telephone: $contact_telephone \n"
                    
."Enquiry: $contact_enquiry";
$mail=mail($pfw_email_to$pfw_subject ,$pfw_message ,$pfw_header ) ;
if (
$mail==0) {
    echo
"There was a problem sending the message please try again later!";
} else {
    echo
"The message has been successfully sent i will try to email you back as soon as possible ".$contact_name."!";
}

?>
Oh after reviewing the code whilst putting together the above example i noticed you have forgotten to end the $mailcontent var in your script after you included the $contact_enquiry var.

Try the above code for the handler php file and it should achieve the desired effect.

Top Tip: Always include user feedback to let them know the mail has been successfully sent or something has went wrong. Also helps you when debugging the code.

Hope this helps
Regards,
Martin
__________________
---------------------------------------------------

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
digitalfusion is offline
Reply With Quote
View Public Profile Visit digitalfusion's homepage!
 
Old 07-28-2008, 08:16 AM Re: does not receive all enquiries from php form using mail() on 1and1 host
Average Talker

Posts: 27
Trades: 0
many thanks! i shall give that a try and see how things go

gav
gavrd1 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to does not receive all enquiries from php form using mail() on 1and1 host
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.46106 seconds with 12 queries