Welcome to WebmasterWorld Guest from 54.242.94.72

Forum Moderators: coopster & jatar k

Message Too Old, No Replies

PHP MAILFORM wont process

php,mail,form, process,send, can not,server,contact,feedback

     

andy106

8:25 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



Hi everyone;

for some reason my phpmail form is not processing, I have an else statement at the bottom of the code to output an error message if mail not sent and I keep getting that message.. PLEASE HELP! lol

here is the code:

<?php

// your name
$recipientname = "company";

// your email
$recipientemail = "d#*$!.com";

// subject of the email sent to you
$subject = "Online-Form Response";

if(isset($_POST['submit'])){
$Name = $HTTP_POST_VARS['Name'];
$adr = $HTTP_POST_VARS['adr'];
$adr2 = $HTTP_POST_VARS['adr2'];
$adr3 = $HTTP_POST_VARS['adr3'];
$city = $HTTP_POST_VARS['city'];
$zip = $HTTP_POST_VARS['zip'];
$phone = $HTTP_POST_VARS['phone'];
$email1 = $HTTP_POST_VARS['email1'];
$creditcardnum = $HTTP_POST_VARS['creditcardnum'];
$cvc = $HTTP_POST_VARS['cvc'];
$note = $HTTP_POST_VARS['note'];

$to = "email";
$subject ="Online form";
$name = $_POST['name'];
$email = $_POST['email1'];
//$company = $_POST['company'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$option = $_POST['method'];
$budget = $_POST['budget'];
$timeframe = $_POST['timeframe'];
$similar_sites = $_POST['similar_sites'];
$description = $_POST['description'];
$headers = 'From: email.com' . "\r\n" .
'Reply-To: email.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSmail-Priority: Normal\n";
$headers .= "X-mailer: php\n";

/*
foreach($_POST['annual'] as $method){
$check_msg .= "Contact Method: $method\n";

}
*/

// check the check boxes
foreach($_POST['checkbox'] as $value){
$check_msg .= "Checked: $value\n\r";

}


// $body = "Name: $name\n Address: $adr\nAddress2: $adr2\n Address3: $adr3\n City: $city\n State: $state\n zip: $zip\n Phone: $phone\n Email: $email1\n Credit Card Number: $creditcardnum\n Exp Month. :expmo$\n Exp Year: $expyr\n $check_msg Option: $budget\n Timeframe: $timeframe\n sites: $similar_sites\n Message: $note\n";

mail($to,$subject,$body);
} else {
echo "We can Not Process your request at this time. ";
}

?>

btw I did try this:

$to = // put in your email address
$send = mail($to, 'TEST', 'Is this thing working?', 'From: chimp@example.com'."\r\n");
if ($send) {
echo 'mail is working';
}
else {
echo 'mail not working';
} this worked.. so the mail settings works.. something whith my script.

rocknbil

9:58 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member rocknbil is a WebmasterWorld Top Contributor of All Time 10+ Year Member



The problem really is your aren't using the mail headers you create. Compare your "this worked" against your script. But an important note, and easy to fix, http_post_vars is long deprecated.

HTTP_POST_VARS [php.net]

Change all those to $_POST['varname'] and that part should be good.

Yes, headers are optional in PHP, but some mail server's won't send a mail with an invalid "from." Using a no-headers method causes a mail to come from "root@example.com" or "apache@example.com."
You've already composed headers there, use them.

Also add this, which is a little better way of trapping the mail failure:

if (mail($to,$subject,$body,$headers)) {
echo "Success";
}
else {
echo "Mail did not send."
}

The only other thing I see is you need a valid email address, guessing you just did this for a public post:

$to = "email";

S/B

$to = "email@example.com"; // or whatever

The last think I'll add, which you probably won't like, this script is horribly vulnerable to injection, I don't see any cleansing of the input being done anywhere. Project for another day, I guess . . .

andy106

10:29 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



Hi Thanks for your help, but still gives me the same error here is the new updated code:

<?php

// your name
$recipientname = "company";

// your email
$recipientemail = "example@example.com";

// subject of the email sent to you
$subject = "Online-Form Response";

if(isset($_POST['submit'])){
$Name = $_POST['Name'];
$adr = $_POST['adr'];
$adr2 = $_POST['adr2'];
$adr3 = $_POST['adr3'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email1 = $_POST['email1'];
$creditcardnum = $_POST['creditcardnum'];
$cvc = $_POST['cvc'];
$note = $_POST['comment'];

$to = "example@example.com";
$subject ="Online form";
$name = $_POST['name'];
$email = $_POST['email1'];
//$company = $_POST['company'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$option = $_POST['method'];
$budget = $_POST['budget'];
$timeframe = $_POST['timeframe'];
$similar_sites = $_POST['similar_sites'];
$description = $_POST['description'];
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: example@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSmail-Priority: Normal\n";
$headers .= "X-mailer: php\n";

/*
foreach($_POST['annual'] as $method){
$check_msg .= "Contact Method: $method\n";

}
*/

// check the check boxes
foreach($_POST['checkbox'] as $value){
$check_msg .= "Checked: $value\n\r";

}

// $body = "Name: $name\n Address: $adr\nAddress2: $adr2\n Address3: $adr3\n City: $city\n State: $state\n zip: $zip\n Phone: $phone\n Email: $email1\n Credit Card Number: $creditcardnum\n Exp Month. :expmo$\n Exp Year: $expyr\n $check_msg Option: $budget\n Timeframe: $timeframe\n sites: $similar_sites\n Message: $note\n";

mail($to,$subject,$body,$headers);
} else {
echo "We can Not Process your request at this time. ";
}

?>

andy106

10:31 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



when I add this if (mail($to,$subject,$body,$headers)) {
echo "Success";
}
else {
echo "Mail did not send."
} i got an error on line 68

Readie

11:14 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



You need a semi colon ; after echo "mail did not send."

So:

if (mail($to,$subject,$body,$headers)) {
echo "Success";
}
else {
echo "Mail did not send.";
}

And you should be good.

[EDIT]

I just noticed this on the code you posted above:

mail($to,$subject,$body,$headers);
} else {
echo "We can Not Process your request at this time. ";
}

You have 2 closers } but only one opener {
You also need "if(" - and to double close the brackets at the end of the if argument there, and to do away with the semi colon as the brackets close

-----

Also, as Rocknbil pointed out above, you're vulnerable to to an injection attack on your database. Change everywhere you have something like this:

$_POST['Name']

to this:

mysql_real_escape_string($_POST['Name'])

To afford yourself some security.

andy106

11:46 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



Hi Readie,

Thanks for your answer... I still can't get it to worl grrrr so annoying.... Please let me know what I am doing wrong.. btw this form is not connected to a database.

Here is the code:
<?php

// your name
$recipientname = "company";

// your email
$recipientemail = "example@example.com";

// subject of the email sent to you
$subject = "Online-Form Response";

if(isset($_POST['submit'])){
$Name = $_POST['Name'];
$adr = $_POST['adr'];
$adr2 = $_POST['adr2'];
$adr3 = $_POST['adr3'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email1 = $_POST['email1'];
$creditcardnum = $_POST['creditcardnum'];
$cvc = $_POST['cvc'];
$note = $_POST['comment'];

$to = "example@example.com";
$subject ="Online form";
$name = $_POST['name'];
$email = $_POST['email1'];
//$company = $_POST['company'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$option = $_POST['method'];
$budget = $_POST['budget'];
$timeframe = $_POST['timeframe'];
$similar_sites = $_POST['similar_sites'];
$description = $_POST['description'];
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: example@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSmail-Priority: Normal\n";
$headers .= "X-mailer: php\n";

// check the check boxes
foreach($_POST['checkbox'] as $value){
$check_msg .= "Checked: $value\n\r";

}

$body = "Name: $name\n Address: $adr\nAddress2: $adr2\n Address3: $adr3\n City: $city\n State: $state\n zip: $zip\n Phone: $phone\n Email: $email1\n Credit Card Number: $creditcardnum\n Exp Month. :expmo$\n Exp Year: $expyr\n $check_msg Option: $budget\n Timeframe: $timeframe\n sites: $similar_sites\n Message: $note\n";

if (mail($to,$subject,$body,$headers)) {
echo "sent!";
}else{
echo "Mail did not send.";

?>

andy106

11:47 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



I did add the } at the end:
if (mail($to,$subject,$body,$headers)) {
echo "sent!";
}else{
echo "Mail did not send.";
}

Readie

11:48 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



if(isset($_POST['submit'])){ 
$Name = $_POST['Name'];
$adr = $_POST['adr'];
$adr2 = $_POST['adr2'];
$adr3 = $_POST['adr3'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email1 = $_POST['email1'];
$creditcardnum = $_POST['creditcardnum'];
$cvc = $_POST['cvc'];
$note = $_POST['comment'];

Is not closed, you need to add a } at the end there. That might fix it, I'll take a look for more mistakes

-----

foreach($_POST['checkbox'] as $value){ 
$check_msg .= "Checked: $value\n\r";

it's not closed

-----

if (mail($to,$subject,$body,$headers)) { 
echo "sent!";
}else{
echo "Mail did not send.";

still not closed. If you have a { you need to have a matching } somewhere - PhP is very unforgiving with syntax errors

[edited by: Readie at 12:19 am (utc) on Jan. 13, 2010]

andy106

11:51 pm on Jan 12, 2010 (gmt 0)

5+ Year Member



I closed is right after the $headers:
'X-Mailer: PHP/' . phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSmail-Priority: Normal\n";
$headers .= "X-mailer: php\n";
} <-- closed

Readie

11:53 pm on Jan 12, 2010 (gmt 0)

WebmasterWorld Senior Member 5+ Year Member



please see my edits :)
Also, it is not closed on the code you posted above

andy106

12:08 am on Jan 13, 2010 (gmt 0)

5+ Year Member



Thanks for all your help.. if you can get this form to work for me I will gladly compensate you... it's still not working:

<?php

// your name
$recipientname = "company";

// your email
$recipientemail = "example@example.com";

// subject of the email sent to you
$subject = "Online-Form Response";

if(isset($_POST['submit'])){
$Name = $_POST['Name'];
$adr = $_POST['adr'];
$adr2 = $_POST['adr2'];
$adr3 = $_POST['adr3'];
$city = $_POST['city'];
$zip = $_POST['zip'];
$phone = $_POST['phone'];
$email1 = $_POST['email1'];
$creditcardnum = $_POST['creditcardnum'];
$cvc = $_POST['cvc'];
$note = $_POST['comment'];

$to = "example@example.com";
$subject ="Online form";
$name = $_POST['name'];
$email = $_POST['email1'];
//$company = $_POST['company'];
$phone = $_POST['phone'];
$city = $_POST['city'];
$state = $_POST['state'];
$country = $_POST['country'];
$option = $_POST['method'];
$budget = $_POST['budget'];
$timeframe = $_POST['timeframe'];
$similar_sites = $_POST['similar_sites'];
$description = $_POST['description'];
$headers = 'From: webmaster@example.com' . "\r\n" .
'Reply-To: example@example.com' . "\r\n" .
'X-Mailer: PHP/' . phpversion();
$headers .= "Content-type: text/html; charset=iso-8859-1\n";
$headers .= "X-Priority: 3\n";
$headers .= "X-MSmail-Priority: Normal\n";
$headers .= "X-mailer: php\n";

}

// check the check boxes
foreach($_POST['checkbox'] as $value){
$check_msg .= "Checked: $value\n\r";
}


$body = "Name: $name\n Address: $adr\nAddress2: $adr2\n Address3: $adr3\n City: $city\n State: $state\n zip: $zip\n Phone: $phone\n Email: $email1\n Credit Card Number: $creditcardnum\n Exp Month. :expmo$\n Exp Year: $expyr\n $check_msg Option: $budget\n Timeframe: $timeframe\n sites: $similar_sites\n Message: $note\n";

if (mail($to,$subject,$body,$headers)) {
echo "sent!";
}else{
echo "Mail did not send.";

}

?>

andy106

12:10 am on Jan 13, 2010 (gmt 0)

5+ Year Member



let me know and I will send you the html too... I need it like asap though.

Thanks.

TheMadScientist

1:38 am on Jan 13, 2010 (gmt 0)

WebmasterWorld Senior Member themadscientist is a WebmasterWorld Top Contributor of All Time 5+ Year Member Top Contributors Of The Month



Are you still needing help with this?

It looks like it could be in the HTML...
I would also look closely at the $_POST['submit'].

The first thing I would do is add these lines:

if(isset($_POST['submit'])){
echo 'Here, Passed Submit Check';
exit();

If you get the echo then start echoing out the variables you need to send the mail and make sure they are being set correctly...

If you can't get it working, please either post the HTML or you can send it to me if you like and I'll have a look at it... Just so I know, are you posting an array() for the checkboxes and are you double checking you are getting the information? print_r($_POST['checkbox']); It doesn't seem to have anything to do with your current issue, but would be good to check and make sure it's getting there... I've had an issue with certain versions of PHP not interpreting POSTed arrays correctly.

andy106

2:10 am on Jan 13, 2010 (gmt 0)

5+ Year Member



TheMadScientist if you want to help I can email you the html file too.

Please give me ur email.

Thank you,

 

Featured Threads

Hot Threads This Week

Hot Threads This Month