Page 1 of 2

Form isn't sending emails or displaying html upon submission

Posted: Mon Sep 26, 2011 11:03 am
by jaydoh73
I hate to ask but can some one do me a huge favor & look my form script over? I'm pretty new to php & I'm stumped. I've made a form within a html page which utilizes a second php file to validate the info & send it to me in an email. However, when I click submit it goes directly to a blank page & none of the e-mails are coming through. I placed the error reporting code in the beginning of the script & have work out a few errors line by line.. but nothing comes up for the issue at hand. I think I may have the html portion wrong. I've pasted the processing code below.. I'm sure it's just some newbie mistake on my part. Any help on this would be greatly appreciated.

<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

// $Id: index.php,v 1.94 2007/12/26...

if(isset($_POST['email'])) {

$email_to = "ordietryingodt@yahoo.com";
$email_subject = "New Recruit To Add";

function died($error) {
// your error code can go here\par
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['QL_Name']) ||
!isset($_POST['Age']) ||
!isset($_POST['Country']) ||
!isset($_POST['Game_Type'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$QL_Name = $_POST['QL_Name']; // required
$Age = $_POST['Age']; // required
$Country = $_POST['Country']; // required
$Game_Type = $_POST['Game_Type']; // not required

$error_message = "";
$Country = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$QL_Name)) {
$error_message .= 'Please enter your residing country.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Age)) {
$error_message .= 'Please enter you QL name.<br />';
}
if(!preg_match($string_exp,$Country)) {
$error_message .= 'Please enter your age.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\\n\\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "QL Name: ".clean_string($QL_Name)."\\n";
$email_message .= "Age: ".clean_string($Age)."\\n";
$email_message .= "Country: ".clean_string($Country)."\\n";
$email_message .= "Game Type: ".clean_string($Game_Type)."\\n";
?>
<!
</head>
<body background="diamondplate.jpg" alink="#c0c0c0" link="#c0c0c0" bgcolor="#000000"
text=#ffffff vLink=#c0c0c0><font size="1">
<p align="center">
<table border="0" cellspacing="0" cellpadding="3" width="100%" bgcolor="#000000"
align=center>
<tbody>
<tr>
<td>
<p align="center"><img border="0" hspace="0" src="ODTlogo1.gif" width="215"
height=89></p>
<p align="center"><img border="0" hspace="0" src="ODTlogo2.gif" width="192"
height=23></p></td></tr></tbody></table></p>
<p></font>&nbsp;</p>
<p align="center"><font size="5" face="Verdana"></font>&nbsp;</p>
<p align="center"><font size="5" face="Verdana"></font>&nbsp;</p>
<p align="center"><font size="5" face="Verdana">Thank you! We will send your clan
invite asap.</font></p>
<p align="center"><font size="5" face="Verdana">We look forward to fragging with
you.</font></p></body></html>
>
<?php
}
?>

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 11:13 am
by Celauran
I don't see mail() being called anywhere, which would explain why no mails are coming through.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 11:21 am
by jaydoh73
Thank you for the quick reply..

I take it I need more than>>> $email_to = "ordietryingodt@yahoo.com";

Also, would that explain why I'm getting the blank screen afterwords? Because the process isn't being completed, or maybe an error that is being reported for some reason?

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 11:27 am
by Celauran
Given that everything is inside your

Code: Select all

if (isset($_POST['email']))
block, I can only assume it's because $_POST['email'] isn't, in fact, set.

Try adding this:

Code: Select all

else
{
    foreach ($_POST as $k => $v)
    {
        echo "$k: $v<br />";
    }
}

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 12:59 pm
by jaydoh73
Forgive the noob question.but where should I add it?

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 1:00 pm
by Celauran
Immediately after your if { } block.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 2:36 pm
by jaydoh73
hmmmm.. no go


Parse error: syntax error, unexpected T_ELSE in /home/odt/public_html/send_form_email.php on line 9

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 2:37 pm
by Celauran
Show me your code?

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 2:40 pm
by jaydoh73
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

// $Id: index.php,v 1.94 2007/12/26...

if(isset($_POST['ordietryingodt@yahoo.com'])) {
$email_to = "ordietryingodt@yahoo.com";
$email_subject = "New Recruit To Add";
$thankyou = "submitted.htm";
else
{
foreach ($_POST as $k => $v)
{
echo "$k: $v<br />";
}
}

function died($error) {
// your error code can go here
echo "We are very sorry, but there were error(s) found with the form you submitted. ";
echo "These errors appear below.<br /><br />";
echo $error."<br /><br />";
die();
}

// validation expected data exists
if(!isset($_POST['QL_Name']) ||
!isset($_POST['Age']) ||
!isset($_POST['Country']) ||
!isset($_POST['Game_Type'])) {
died('We are sorry, but there appears to be a problem with the form you submitted.');
}

$QL_Name = $_POST['QL_Name']; // required
$Age = $_POST['Age']; // required
$Country = $_POST['Country']; // required
$Game_Type = $_POST['Game_Type']; // not required

$error_message = "";
$Country = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$QL_Name)) {
$error_message .= 'Please enter your residing country.<br />';
}
$string_exp = "/^[A-Za-z .'-]+$/";
if(!preg_match($string_exp,$Age)) {
$error_message .= 'Please enter you QL name.<br />';
}
if(!preg_match($string_exp,$Country)) {
$error_message .= 'Please enter your age.<br />';
}
if(strlen($error_message) > 0) {
died($error_message);
}
$email_message = "Form details below.\\n\\n";

function clean_string($string) {
$bad = array("content-type","bcc:","to:","cc:","href");
return str_replace($bad,"",$string);
}

$email_message .= "QL Name: ".clean_string($QL_Name)."\\n";
$email_message .= "Age: ".clean_string($Age)."\\n";
$email_message .= "Country: ".clean_string($Country)."\\n";
$email_message .= "Game Type: ".clean_string($Game_Type)."\\n";
}
?>
<?php
?>

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 2:43 pm
by Celauran
No, you need to put it after the if {} block, not inside it.

Code: Select all

<?php

error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);

// $Id: index.php,v 1.94 2007/12/26...

if (isset($_POST['ordietryingodt@yahoo.com']))
{
    $email_to = "ordietryingodt@yahoo.com";
    $email_subject = "New Recruit To Add";
    $thankyou = "submitted.htm";

    function died($error)
    {
        // your error code can go here
        echo "We are very sorry, but there were error(s) found with the form you submitted. ";
        echo "These errors appear below.<br /><br />";
        echo $error . "<br /><br />";
        die();
    }

    // validation expected data exists
    if (!isset($_POST['QL_Name']) ||
            !isset($_POST['Age']) ||
            !isset($_POST['Country']) ||
            !isset($_POST['Game_Type']))
    {
        died('We are sorry, but there appears to be a problem with the form you submitted.');
    }

    $QL_Name = $_POST['QL_Name']; // required
    $Age = $_POST['Age']; // required
    $Country = $_POST['Country']; // required
    $Game_Type = $_POST['Game_Type']; // not required

    $error_message = "";
    $Country = "/^[A-Za-z .'-]+$/";
    if (!preg_match($string_exp, $QL_Name))
    {
        $error_message .= 'Please enter your residing country.<br />';
    }
    $string_exp = "/^[A-Za-z .'-]+$/";
    if (!preg_match($string_exp, $Age))
    {
        $error_message .= 'Please enter you QL name.<br />';
    }
    if (!preg_match($string_exp, $Country))
    {
        $error_message .= 'Please enter your age.<br />';
    }
    if (strlen($error_message) > 0)
    {
        died($error_message);
    }
    $email_message = "Form details below.\\n\\n";

    function clean_string($string)
    {
        $bad = array("content-type", "bcc:", "to:", "cc:", "href");
        return str_replace($bad, "", $string);
    }

    $email_message .= "QL Name: " . clean_string($QL_Name) . "\\n";
    $email_message .= "Age: " . clean_string($Age) . "\\n";
    $email_message .= "Country: " . clean_string($Country) . "\\n";
    $email_message .= "Game Type: " . clean_string($Game_Type) . "\\n";
}
else
{
    foreach ($_POST as $k => $v)
    {
        echo "$k: $v<br />";
    }
}

?>
Also, please use

Code: Select all

 for your PHP code.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 3:09 pm
by jaydoh73
Sorry about the syntax.

Now it’s just showing the form results in plain text on a white page, but I think it’s a step in the right direction. I’ll have to look at it more later tonight.

Thank you for helping me out with this by the way.. It’s much appreciated.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 3:12 pm
by Celauran
jaydoh73 wrote:Now it’s just showing the form results in plain text on a white page
That's intended. Can you confirm that $_POST['email'] is not in that list?

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 4:02 pm
by jaydoh73
if (isset($_POST['ordietryingodt@yahoo.com'])) << is that correct?.. The e-mail still isn't going through.

I need it to either redirect to a thank you page or display a message on the form page upon submission.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 4:10 pm
by Celauran
No, that's not correct.

Code: Select all

if (isset($_POST['email']))
checks if the $_POST array (which is populated when your form is submitted) contains a key called 'email' -- basically checks if the form has a field named 'email' and if that field contains a value. Your processing page is not executing the code inside that conditional block, which means that $_POST['email'] isn't set. Have you double-checked the name given to the form input that contains the email address? I figured displaying the contents of $_POST might help you spot a typo or naming error.

Re: Form isn't sending emails or displaying html upon submis

Posted: Mon Sep 26, 2011 8:40 pm
by jaydoh73
I added an email field on the form & the following block to the processing script...

Code: Select all

$headers = 'From: '.$email_from."\r\n".
'Reply-To: '.$email_from."\r\n" .
'X-Mailer: PHP/' . phpversion();
@mail($email_to, $email_subject, $email_message, $headers);
Now I'm getting this...

We are very sorry, but there were error(s) found with the form you submitted. These errors appear below.

We are sorry, but there appears to be a problem with the form you submitted.