April 24, 200917 yr Hi Developers. I am trying desperately to set up PHP driven contact form on my website. I have ensured my server type is Linux and I have ensured that PHP is enabled through my hosting. I cannot get any sort of php script to successfully send an email to my webmail account, so I asked my hosting providers and they replied: "Our engineers have confirmed that in most of the cases with email not being sent they are seeing this issue is being caused by the server rules for these scripts being more stringently enforced and the –f command not being used within the script as is required on our servers. All outbound email must be routed through our outgoing email servers or it will not be delivered, it is not possible to send email from a script directly to a third party SMTP server. In order for the script to work, you need to specify, via a fifth -f parameter, the domain from which the mail is being sent. The PHP component uses SMTP, and all Streamline.net' SMTP servers have filters which ensure that the data returned by either the first or fifth mail parameter relates to one of your domains hosted by Streamline.net. The final part of the script thanks the visitor for the message. This is done by sending an HTTP header back to the visitor's browser telling it to load a file called thankyou.html from your domain. The /header/function allows you to send any HTTP header back to the browser. Here is a sample of a working PHP mail script (you will need to fill in details): $from = "thefromemailaddress@domain"; mail("recipient@", "Test mail from PHP mail","This is a test PHP Email","From: $from", "-f$from" ); print "Mail sent"; ?> This script if edited properly will prove the working of the PHP mail() function on our servers." SO, when testing this it works fine and a test mail is sent to my account. HOWEVER I still cannot get ANY kind of full contact form (with spam protection etc) script or even a basic script to work even when including the "$from" parameter. Can anyone help please? It is driving me absolutely mad!!! My PHP code is here: <?php /******************************************************************************* * Title: PHP Contact Form with Spam Protection * Version: 1.1 @ April 1, 2009 * Author: Vishal P. Rao * Website: http://www.work-at-home-forum.com ******************************************************************************** * COPYRIGHT NOTICE * Copyright 2009 Vishal P. Rao. All Rights Reserved. * * This script may be used and modified free of charge by anyone * AS LONG AS COPYRIGHT NOTICES AND ALL THE COMMENTS REMAIN INTACT. * By using this code you agree to indemnify Vishal P. Rao or * www.work-at-home-forum.com from any liability that might arise from * it's use. * * Selling the code for this program, in part or full, without prior * written consent is expressly forbidden. * * Obtain permission before redistributing this software over the Internet * or in any other medium. In all cases copyright and header must remain * intact. This Copyright is in full effect in any country that has * International Trade Agreements with the India * * Removing any of the copyright notices without purchasing a license * is illegal! *******************************************************************************/ /******************************************************************************* * Script configuration - Refer README.txt *******************************************************************************/ /* Email address where the messages should be delivered */ $to = 'info@samdelara.co.uk'; $from = "enquiry@samdelara.co.uk"; /* This will be appended to the subject of contact form message */ $subject_prefix = 'My Website Contact'; /* Directory path of files. DO NOT add trailing slash - not /forms/ */ $path_to_files = ''; /* Form width including px */ $form_width = '450px'; /* Form background color */ $form_background = '#F7F8F7'; /* Form border color */ $form_border = '#CCCCCC'; /* Form border style. Examples - dotted, dashed, solid, double */ $form_border_style = 'solid'; /* Empty/Invalid fields will be highlighted in this color */ $field_error_color = '#FF0000'; /* Thank you message to be displayed after the form is submitted. Can include HTML tags. Write your message between <!-- Start message --> and <!-- End message --> */ $thank_you_message = <<<EOD <!-- Start message --> <p>We have received your message. If required, we'll get back to you as soon as possible.</p><br /><br /><br /><br /><br /><br /><br /><br /> <!-- End message --> EOD; /******************************************************************************* * Do not change anything below, unless of course you know very well * what you are doing *******************************************************************************/ $label_name = 'Name'; $label_email = 'Email'; $label_subject = 'Subject'; $label_message = 'Message'; $label_code = 'Code'; if (!isset($_POST['submit'])) { $name_value = ''; $email_value = ''; $subject_value = ''; $message_value = ''; $label_name_empty_style = ''; $label_email_empty_style = ''; $label_email_invalid = ''; $label_subject_empty_style = ''; $label_message_empty_style = ''; $label_code_empty_style = ''; $label_code_invalid = ''; showForm(); } else { //form submitted $error = 0; if(!empty($_POST['name'])) { $name_value = clean_var($_POST['name']); } else { $name_value = ''; $error = 1; $label_name_empty_style = 'color:#FF0000;'; } if(!empty($_POST['email'])) { $email_value = clean_var($_POST['email']); if (!ereg("^([a-zA-Z0-9_\.-]+)@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.)|(([a-zA-Z0-9\-]+\.)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\]?)$", $_POST['email'])) { $error = 1; $label_email_empty_style = 'color:#FF0000;'; $label_email_invalid = '<strong><span style="color:#FF0000;">Invalid email</span><strong>'; } } else { $email_value = ''; $error = 1; $label_email_empty_style = 'color:#FF0000;'; } if(!empty($_POST['subject'])) { $subject_value = clean_var($_POST['subject']); } else { $error = 1; $label_subject_empty_style = 'color:#FF0000;'; $subject_value = ''; } if(!empty($_POST['message'])) { $message_value = clean_var($_POST['message']); } else { $message_value = ''; $error = 1; $label_message_empty_style = 'color:#FF0000;'; } if(empty($_POST['captcha_code'])) { $error = 1; $label_code_empty_style = 'color:#FF0000;'; } else { include_once $_SERVER['DOCUMENT_ROOT'] . "$path_to_files/securimage.php"; $securimage = new Securimage(); $valid = $securimage->check($_POST['captcha_code']); if(!$valid) { $error = 1; $label_code_empty_style = 'color:#FF0000;'; $label_code_invalid = '<strong><span style="color:#FF0000;">Incorrect code</span></strong>'; } } if ($error == 1) { echo "\n<span style=\"font-weight:bold;font-size:90%;\">Please correct/enter field(s) in red.</span>\n\n"; showForm(); } else { $message = "$name_value\n$email_value\n\nMessage:\n$message_value"; mail($to,"$subject_prefix - $subject_value",$message,"From: $name_value <$email_value>"); echo $GLOBALS['thank_you_message']; echo "\n"; } } //else submitted function showForm() { global $path_to_files; echo <<<EOD <div style="width:{$GLOBALS['form_width']};vertical-align:top;text-align:left;background-color:{$GLOBALS['form_background']};border: 1px {$GLOBALS['form_border']} {$GLOBALS['form_border_style']};overflow:visible;"> <form method="post" class="contact"> <table style="padding:5px;text-align:left;"> <tr> <td style="width:120px;"><span style="font-weight:bold;{$GLOBALS['label_name_empty_style']}">{$GLOBALS['label_name']}</span></td> <td> <input type="text" name="name" value="{$GLOBALS['name_value']}" /> </td> </tr> <tr> <td><span style="font-weight:bold;{$GLOBALS['label_email_empty_style']}">{$GLOBALS['label_email']}</span></td> <td> <input type="text" name="email" value="{$GLOBALS['email_value']}" /> {$GLOBALS['label_email_invalid']} </td> </tr> <tr> <td><span style="font-weight:bold;{$GLOBALS['label_subject_empty_style']}">{$GLOBALS['label_subject']}</span></td> <td> <input type="text" name="subject" value="{$GLOBALS['subject_value']}" /> </td> </tr> <tr> <td style="vertical-align:top"><span style="font-weight:bold;{$GLOBALS['label_message_empty_style']}">{$GLOBALS['label_message']}</span></td> <td> <textarea name="message" cols="40" rows="6">{$GLOBALS['message_value']}</textarea> </td> </tr> <tr> <td> </td> <td><img id="captcha" src="$path_to_files/securimage_show.php" alt="CAPTCHA Image" /></td> </tr> <tr> <td style="vertical-align:top"><span style="font-weight:bold;{$GLOBALS['label_code_empty_style']}">{$GLOBALS['label_code']}</span></td> <td> <input type="text" name="captcha_code" size="10" maxlength="5" /> {$GLOBALS['label_code_invalid']}<br /> (Please enter the text in the image above. Text is not case sensitive.)<br /> <a href="#" onclick="document.getElementById('captcha').src = '$path_to_files/securimage_show.php?' + Math.random(); return false">Click here if you cannot recognize the code.</a> </td> </tr> <tr> <td colspan="2"><span style="font-size:90%;font-weight:bold;">All fields are required.</span></td> </tr> <tr> <td colspan="2"> <input type="submit" name="submit" value="Submit" style="border:1px solid #999;background:#E4E4E4;margin-top:5px;" /> </td> </tr> </table> </form> <div style="text-align:right;font-size:80%;"><a href="http://www.work-at-home-forum.com/8_12714_0.html" title="PHP Contact Form">PHP Contact Form v1.1</a></div> </div> EOD; } function clean_var($variable) { $variable = strip_tags(stripslashes(trim(rtrim($variable)))); return $variable; } ?> Sam
April 24, 200917 yr This line here mail($to,"$subject_prefix - $subject_value",$message,"From: $name_value <$email_value>"); You havent included the [b]"From: $from", "-f$from"[/b] Try mail($to,"$subject_prefix - $subject_value",$message,"[b]From: $from", "-f$from"[/b]); and see of it sends Pat
April 24, 200917 yr Author Pat, Thank you very much, that worked a treat! Much appreciated. Thanks again. Regards. Sam
Create an account or sign in to comment