Skip to content
View in the app

A better way to browse. Learn more.

Web Designer Forum

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Need help with php script

Featured Replies

Hi Guys.

 

Wondering if anyone can help. I've been trying to sort this out for the last 3 days and can't seem to get anywhere. I'm currently working on a php mail script with jquery & php validation. The page woks well and sends the users contact details to the server, but refuses to display anything in the (From:) (see attached) so wont forward it to the virgin media email.

 

post-35145-0-10182700-1385757601_thumb.jpg

 

The script I have is:

<?php
//If the form is submitted
if(isset($_POST['submit'])) {

	//Check to make sure that the name field is not empty
	if(trim($_POST['contactname']) == '') {
		$hasError = true;
	} else {
		$name = trim($_POST['contactname']);
	}
	
	//Check to make sure that the name field is not empty
	if(trim($_POST['postcode']) == '') {
		$hasError = true;
	} else {
		$postcode = trim($_POST['postcode']);
	}

	//Check to make sure sure that a valid email address is submitted
	if(trim($_POST['number']) == '') {
		$hasError = true;
	} else {
		$number = trim($_POST['number']);
	}
	
	//Check to make sure that the subject field is not empty
	if(trim($_POST['postcode']) == '') {
		$hasError = true;
	} else {
		$postcode = trim($_POST['postcode']);
	}

	//Check to make sure sure that a valid email address is submitted
	if(trim($_POST['email']) == '')  {
		$hasError = true;
	} else if (!eregi("^[A-Z0-9._%-]+@[A-Z0-9._%-]+\.[A-Z]{2,4}$", trim($_POST['email']))) {
		$hasError = true;
	} else {
		$email = trim($_POST['email']);
	}

	//Check to make sure comments were entered
	if(trim($_POST['message']) == '') {
		$hasError = true;
	} else {
		if(function_exists('stripslashes')) {
			$message = stripslashes(trim($_POST['message']));
		} else {
			$message = trim($_POST['message']);
		}
	}

	//If there is no error, send the email
	if(!isset($hasError)) {
		$
		$emailTo = 'contact@r-m-t.org.uk'; 
		$body = "Name: $name \n\n Email: $email \n\n Contact No.: $number \n\nPost Code: $postcode \n\n Message:\n $message";
		$headers = 'Website Contact Form';

		mail($emailTo, $headers, $body );
		$emailSent = true;
	}
}
?>

can anyone help or suggest a way to work round virgins spam filters to allow.

 

Thanks

The mail function should be:

 

mail($to, $subject, $message, $headers);

In your case:

 

mail($emailTo, $subject, $body, $headers);

 

Rename $headers to $subject

 

Your new $headers should be:

 

$headers = 'From: whatever@whatever';

 

Edit: For example:

 

if(!isset($hasError)) {

		$emailTo = 'contact@r-m-t.org.uk'; 
		$body = "Name: $name \n\n Email: $email \n\n Contact No.: $number \n\nPost Code: $postcode \n\n Message:\n $message";
		$subject = 'Website Contact Form';
		$headers = 'From: whatever@whatever';
 
		mail($emailTo, $subject, $body, $headers);
		$emailSent = true;
}

 

Check out http://php.net/manual/en/function.mail.php#example-3374

Edited by Gibbs

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.