...

View Full Version : form to email problem



Razzy
08-01-2012, 01:03 PM
hey people, i have this order form for a website which would send the results to an email address. for some reason it does not seem to be working the php coding is shown below:




<?php
$to = "razzyc@hotmail.co.uk";//<== update the email address
$email_subject = "New Form submission";
$email_body = "You have received a new message from the user $first_name.\n".



$first_name = $_REQUEST['first_name'] ;
$last_name = $_REQUEST['last_name'] ;
$first_line_address = $_REQUEST['address'] ;
$post_code = $_REQUEST['postcode'] ;
$tel_number = $_REQUEST['tel_no'] ;
$email_address = $_REQUEST['email'] ;


function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}

?>




and the coding for the form is:




<form name="order" method="post" id="orderForm" action="test23.php">


1. First Name: <input type="text" name="first_name" />
<br/>
2. Last Name: <input type="text" name="last_name" />
<br/>
3. Firstline Address: <input type="text" name="address"/>
<br/>
4. Post Code: <input type="text" name="postcode"/>
<br/>
5. Telephone No: <input type="text" name="tel_no"/>
<br/>
6. Email Address: </td> <td><input type="email" name="email"/>
<br/>
</form>



would really appreciate it if someone could help

thank you

AndrewGSW
08-01-2012, 01:21 PM
Your code doesn't include the mail() method to actually send the email :)

mlseim
08-01-2012, 01:22 PM
Use Google to find a PHP example for: PHP contact form email

You're missing a lot of things ... including the mail() function itself.

daneth
08-01-2012, 01:26 PM
Just to add... in case the email address you are sending from requires authentication, I would suggest you look up on google phpmailer.

This is a class that will allow you to send emails through servers that require authentication.

Razzy
08-01-2012, 08:08 PM
hey people, thank you for that, i have made some changes to it, but for some reason and error message comes up.(internal server error)

the php code is as follows:




$webmaster_email = "musharof@al-rahmah.co.uk";


$first_name = $_REQUEST['first_name'] ;
$last_name = $_REQUEST['last_name'] ;
$email_address = $_REQUEST['email'] ;



function isInjected($str) {
$injections = array('(\n+)',
'(\r+)',
'(\t+)',
'(%0A+)',
'(%0D+)',
'(%08+)',
'(%09+)'
);
$inject = join('|', $injections);
$inject = "/$inject/i";
if(preg_match($inject,$str)) {
return true;
}
else {
return false;
}
}


else {
mail( "$webmaster_email", "Feedback Form Results",
$first_name, "From: $email_address" );
header( "thankyou" );
}
?>




i have not finished it yet so please ignore that fact that there is not authentication etc


thank you

AndrewGSW
08-01-2012, 08:41 PM
Do you have a mail server running?

Razzy
08-02-2012, 12:51 PM
sorry andrew it is working now, i get an email sent to the email address as soon as i click the submit button, however i have a new problem now :(

i am trying to output the results on the email body so that the filled in fields will appear as follows:

first name: blahblah
last name: blahblahblah
first line address: 123 new street

i have used the following codes however it does not seem to work



<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email

{


//send email
$email = $_REQUEST['email'] ;
mail("musharof@al-rahmah.co.uk", "Feedback Form Results",
"From:" . $email,

First name: <?php echo $_POST["first_name"]; ?>
Last name: <?php echo $_POST["last_name"]; ?>
Address: <?php echo $_POST["address"]; ?>

echo "Thank you for using our mail form";
}

?>

ECoode
08-02-2012, 01:35 PM
You should try this:


<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email

{


//send email
$to = "musharof@al-rahmah.co.uk";
$subject = "Emails subject here";
$email = $_REQUEST['email'] ;

// To allow HTML codes to email!
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message = "
<html>
<head><title>Emails subject here</title></head>
<body>
<p>Email is from ".$email." </p>
<p>First name: ".$_POST["first_name"]."<br />
Last name: ".$_POST["last_name"]."<br />
Address: ".$_POST["address"]."</p>
</body>
</html>";

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

echo "Thank you for using our mail form";
}

?>

EDIT: You should read this; PHP: mail -Manual (http://php.net/manual/en/function.mail.php)
Should working well, report if get errors :o

Razzy
08-02-2012, 09:51 PM
hey ecoode thanx for that it worked apart from a small problem, for some reason the senders email address does not appear on the "from" section on the email.

i added......"From:" . $email........ within mail() but it still doesnt work

as you can see below:




<?php
if (isset($_REQUEST['email']))
//if "email" is filled out, send email

{


//send email
$to = "musharof@al-rahmah.co.uk";
$subject = "order form submitted";
$email = $_REQUEST['email'] ;

// To allow HTML codes to email!
$headers = 'MIME-Version: 1.0' . "\r\n";
$headers .= 'Content-type: text/html; charset=iso-8859-1' . "\r\n";

$message = "
<html>
<head><title>Order placed</title></head>
<body>
<p>Email is from ".$email." </p>
<p>First name: ".$_POST["first_name"]."<br />
Last name: ".$_POST["last_name"]."<br />
Address: ".$_POST["address"]."</p>
</body>
</html>";

mail($to,$subject,$message,$headers, "From:" . $email);

echo "Thank you for using our mail form";
}

?>

ECoode
08-02-2012, 10:05 PM
You should use my original code, as you might noticed that I added part:

<p>Email is from ".$email." </p>
to $message variable to show on every email who sended it.

If you still wanna add that 'From' part you can add this

$headers .= 'From: $email' . "\r\n";
and change mail function back to where it was.

Razzy
08-03-2012, 01:12 AM
thanks ecoode i used



$headers .= 'From: $email' . "\r\n";


but still with no success...for some reason on the "from" field of the email, i get random email address such as: From: "$email"@boscgi3406.eigbox.net

but anyhow i have decided to just use the code that you first gave me :)

thank you very much

AndrewGSW
08-03-2012, 01:19 AM
Variables do not expand within single quotes, nor do escaped characters:


$headers .= "From: $email\r\n";

Razzy
08-03-2012, 01:08 PM
thank you very much andrewGSW it perfectly works now :)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum