...

View Full Version : Php 5



kamaro
01-29-2012, 12:53 AM
I have a contact form which users can write a message a click submit. I want it to send all messages to a email address but its not working. I herd I need PHP 5 for this to work. My question is how to I DL php 5 and do i need to do anything to it after i DL or just put it in the site folder. My next *dumb* question is do I need a server or domain to have the messages sent work? Thanks

submit.php


<?php

/* config start */

$emailAddress = 'xxx@hotmail.com';

/* config end */


require "../php/class.phpmailer.php";

session_name("fancyform");
session_start();


foreach($_POST as $k=>$v)
{
if(ini_get('magic_quotes_gpc'))
$_POST[$k]=stripslashes($_POST[$k]);

$_POST[$k]=htmlspecialchars(strip_tags($_POST[$k]));
}


$err = array();

if(!checkLen('name'))
$err[]='The name field is too short or empty!';

if(!checkLen('email'))
$err[]='The email field is too short or empty!';
else if(!checkEmail($_POST['email']))
$err[]='Your email is not valid!';

if(!checkLen('subject'))
$err[]='You have not selected a subject!';

if(!checkLen('message'))
$err[]='The message field is too short or empty!';

if((int)$_POST['captcha'] != $_SESSION['expect'])
$err[]='The captcha code is wrong!';


if(count($err))
{
if($_POST['ajax'])
{
echo '-1';
}

else if($_SERVER['HTTP_REFERER'])
{
$_SESSION['errStr'] = implode('<br />',$err);
$_SESSION['post']=$_POST;

header('Location: '.$_SERVER['HTTP_REFERER']);
}

exit;
}


$msg=
'Name: '.$_POST['name'].'<br />
Email: '.$_POST['email'].'<br />
IP: '.$_SERVER['REMOTE_ADDR'].'<br /><br />

Message:<br /><br />

'.nl2br($_POST['message']).'

';


$mail = new PHPMailer();
$mail->IsMail();

$mail->AddReplyTo($_POST['email'], $_POST['name']);
$mail->AddAddress($emailAddress);
$mail->SetFrom($_POST['email'], $_POST['name']);
$mail->Subject = "A new ".mb_strtolower($_POST['subject'])." from ".$_POST['name']." | contact form feedback";

$mail->MsgHTML($msg);

$mail->Send();


unset($_SESSION['post']);

if($_POST['ajax'])
{
echo '1';
}
else
{
$_SESSION['sent']=1;

if($_SERVER['HTTP_REFERER'])
header('Location: '.$_SERVER['HTTP_REFERER']);

exit;
}

function checkLen($str,$len=2)
{
return isset($_POST[$str]) && mb_strlen(strip_tags($_POST[$str]),"utf-8") > $len;
}

function checkEmail($str)
{
return preg_match("/^[\.A-z0-9_\-\+]+[@][A-z0-9_\-]+([.][A-z0-9_\-]+)+[A-z]{1,4}$/", $str);
}

?>

Dan13071992
01-29-2012, 01:33 AM
firstly, are you using a local host, or are you being hosted by a hosting service?

secondly, if you are using a hosting service, I think alomst every single host out there at the moment is using php 5, and you cannot simply place php 5 in a folder on your server and make it work, the host has to update their servers.

thirdly, even local host servers such as Wamp server have options to download many different versions of php, but their "recommended" download is usually the latest version of php.

so what i feel would be the answer to your question, is, yes you will need a version of php, however you can only use the one your host offers, or if using local host programs, you can download the latest that that program offers from their site.

I hope this has answered your question.

Dan

kamaro
01-29-2012, 01:39 AM
You definitely answered my question. No I do not have a host yet. Just wondering now if you know any good FREE ones I can use for now just to see if this contact form feature works properly.

Dan13071992
01-29-2012, 01:42 AM
im sorry, i dont know any free hosts :s i know a cheap host if that helps? if so I dont think Im allowed to post it here as it might be classed as advertising, however if a moderator wants to step in and let me know then Im sure that if you would like those details and its ok with the mods, i can share the link with you.

Glad I could help.

Dan

kamaro
01-29-2012, 01:45 AM
Ok well thanks anyway

Dan13071992
01-29-2012, 01:47 AM
No problem.

I hope you get it working soon, and you can find hosting ok. If I stumble accross any free hosts, Ill let you know. although im sure you could probably do a quick google search and find tons :)

All the best.

Dan

jmj001
01-29-2012, 11:50 AM
just google: free web hosting with php

there's a million million million of them....

well, maybe not quite that many..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum