Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Not Receiving email with form information

Status
Not open for further replies.

braves07

Technical User
Apr 24, 2007
40
US
Hi, I have a php script that I'm trying to use to process a form on a website. Can you please tell me if I'm doing something wrong? I'm not receiving the email.

Code:
<?php
// Receiving variables
@$item_name = addslashes($_POST['item_name']);
@$quantity = addslashes($_POST['quantity']);
@$amount = addslashes($_POST['amount']);
@$firstname = addslashes($_POST['firstname']);
@$lastname = addslashes($_POST['lastname']);
@$address1 = addslashes($_POST['address1']);
@$address2 = addslashes($_POST['address2']);
@$city = addslashes($_POST['city']);
@$state = addslashes($_POST['state']);
@$zip = addslashes($_POST['zip']);
@$company = addslashes($_POST['company']);
@$occupation = addslashes($_POST['occupation']);
@$email = addslashes($_POST['email']);
@$phone1 = addslashes($_POST['phone1']);
@$phone2 = addslashes($_POST['phone2']);
@$phone3 = addslashes($_POST['phone3']);
@$phonetype = addslashes($_POST['phonetype']);

// Validation
if ( $amount < 0)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}
if ( $amount > 500)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}

if (strlen($amount) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid amount</font></p>");
}

if (strlen($firstname) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}
if (strlen($firstname) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}

if (strlen($firstname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid firstname</font></p>");
}

if (strlen($lastname) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}
if (strlen($lastname) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}

if (strlen($lastname) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid lastname</font></p>");
}

if (strlen($address1) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}
if (strlen($address1) >100)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}

if (strlen($address1) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid address1</font></p>");
}

if (strlen($city) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}
if (strlen($city) >30)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}

if (strlen($city) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid city</font></p>");
}

if (strlen($zip) <5)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}
if (strlen($zip) >10)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}

if (strlen($zip) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid zip</font></p>");
}

if (strlen($occupation) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}
if (strlen($occupation) >20)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}

if (strlen($occupation) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid occupation</font></p>");
}

if (strlen($email) <1)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}
if (strlen($email) >100)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($email) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid email</font></p>");
}

if (strlen($phone1) <3)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}
if (strlen($phone1) >3)
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}

if (strlen($phone1) == 0 )
{
die("<p align='center'><font face='Arial' size='3' color='#FF0000'>Please enter a valid phone1</font></p>");
}

//Sending Email to form owner
$pfw_header = "From: $email\n"
  . "Reply-To: $email\n";
$pfw_subject = "form test";
$pfw_email_to = "email@email.com";
$pfw_message = "item_name: $item_name\n"
. "quantity: $quantity\n"
. "amount: $amount\n"
. "firstname: $firstname\n"
. "lastname: $lastname\n"
. "address1: $address1\n"
. "address2: $address2\n"
. "city: $city\n"
. "state: $state\n"
. "zip: $zip\n"
. "company: $company\n"
. "occupation: $occupation\n"
. "email: $email\n"
. "phone1: $phone1\n"
. "phone2: $phone2\n"
. "phone3: $phone3\n"
. "phonetype: $phonetype\n";
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header ) ;

header("Location: [URL unfurl="true"]https://www.paypal.com/cgi-bin/webscr");[/URL]
?>

Thanks,

braves07
 
First, quit with all that use of "@". It is an error supression operator, and error supression during debugging is usually considered counterproductive. And once your script it in production, you should be handling errors, not suppressing them.

Second, SMTP specifies a newline as "\r\n". Some mail servers care about this and some don't, so it's best to use both characters.


Now, have you verified that your script can send simple mail?



Want the best answers? Ask the best questions! TANSTAAFL!
 
No I have not verified if I can send simple mail... I don't even know how to. I tried filling out the form, it redirects me correctly but no mail has came through. I'm very new to php so I'm not sure what is going wrong. Do I just remove the @ and it will work?
 
I have no idea whether removing the @s will make it work. All I know is that removing them might show different behavior.

If you do not know how to write a simple mailing script, I recommend that you start searching the PHP online manual at . It is not only one of the best resource for PHP available, it is one of the best resources of its type on the internet. And it has a lot of example code.



Want the best answers? Ask the best questions! TANSTAAFL!
 
Alright, this is getting frustrating :(. The mail function is correct "@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header );" But it still isn't sending the mail. If I don't fill a required field out.. it gives me the correct error, when I submit the form it redirects me correctly, everything is working properly except I'm not getting the mail. I tried removing the last line that redirects still no mail. I added the \r\n still no mail. Someone please help.
 
Follow Sleipnir's suggestion and remove the @ from the mail sending line:
Code:
@mail($pfw_email_to, $pfw_subject ,$pfw_message ,$pfw_header );

If you get an error message, post it here so we can further debug. If no error is generated, then that means that the mail function is successfully handing the mail over to the configured smtp server, and you should check your mail server settings and see if they are indeed correct for sending mails.

----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.
 
and check your mail logs too.

as vacunita says: check your php.ini settings for smtp hosts and/or sendmail paths.

and start simple, does this work? (change the to and from to real email addresses that are allowed to relay through your servers)

Code:
$to = "example@example.com";
$from = "example@example.com";
$subject = "test message";
$message = "test content";
mail ($to, $subject, $message, "From: $from\r\n");
 
Thanks for all your help everyone. I really appreciate it. I'm going to work on those suggestions.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top