Jump to content

I need a little help with my code


jelah

Recommended Posts

Im really really new at php and ive got a form but the email is not sending, im sure its something simple but if anyone can take a look that would be great.

 

<?

// This function delivers a template with the error message
function pgerror($string){
include 'head.inc';
echo "<font color=\"#FF0000\">Error: $string</font>";
include 'foot.inc';
exit();
}

function pgsuccess($string){
include 'head.inc';
echo "<font color=\"green\">Thank you $string</font>";
include 'foot.inc';
exit();
}


// These functions validate required feilds
if (empty($_POST['first'])){
pgerror('Please enter your first name.');
}
else {
$first = $_POST['first'];
}

if (empty($_POST['last'])){
pgerror('Please enter your last name.');
}
else {
$last = $_POST['last'];
}

if (empty($_POST['address'])){
pgerror('Please enter your address.');
}
else {
$address = $_POST['address'];
}

if (empty($_POST['city'])){
pgerror('Please select your city.');
}
else {
$city = $_POST['city'];
}

if (empty($_POST['state'])){
pgerror('Please enter your state or province.');
}
else {
$state = $_POST['state'];
}

if (empty($_POST['postalcode'])){
pgerror('Please enter your postal code/zip code.');
}
else {
$postalcode = $_POST['postalcode'];
}

if (empty($_POST['country'])){
pgerror('Please select your country.');
}
else {
$country = $_POST['country'];
}

if (empty($_POST['email'])){
pgerror('Please enter your email.');
}
else {
$email = $_POST['email'];
}


if (empty($_POST['phone1'])){
pgerror('Please enter your phone number.');
}
else {
$phone1 = $_POST['phone1'];
}
if (empty($_POST['phone2'])){
pgerror('Please enter your phone number.');
}
else {
$phone2 = $_POST['phone2'];
}
if (empty($_POST['phone3'])){
pgerror('Please enter your phone number.');
}
else {
$phone3 = $_POST['phone3'];
}

if (empty($_POST['gender'])){
pgerror('Please enter your gender.');
}
else {
$gender = $_POST['gender'];
}

if (empty($_POST['why'])){
pgerror('Please complete all required feilds.');
}
else {
$why = $_POST['why'];
}

if (empty($_POST['reason1'])){
pgerror('Please complete all required feilds.');
}
else {
$reason1 = $_POST['reason1'];
}
if (empty($_POST['reason2'])){
pgerror('Please complete all required feilds.');
}
else {
$reason2 = $_POST['reason2'];
}
if (empty($_POST['reason3'])){
pgerror('Please complete all required feilds.');
}
else {
$reason3 = $_POST['reason3'];
}

pgsuccess('for your application!');

$todayis = date("l, F j, Y, g:i a") ;
$subject = 'Photovoice Participant Application Form';

$notes = stripcslashes("
Name: $first $last\n
Address: $address\n
City: $city\n
Province: $state\n
Postal Code: $postalcode\n
Country: $country\n
Email: $email\n
Phone: $phone1-$phone2-$phone3\n
Gender (1=Male 2=Female): $gender\n
Parent Permission: $party\n
Parent Name: $parentnamefirst\n
Why: $why\n
Reason 1: $reason1\n
Reason 2: $reason2\n
Reason 3: $reason3\n
");

$message = "
$todayis [EST] \n
Message: $notes \n
";
$from = "From: $email\r\n";


mail("[email protected]", $subject, $message, $from);
?>

Link to comment
https://forums.phpfreaks.com/topic/162865-i-need-a-little-help-with-my-code/
Share on other sites

I tried this and it still isnt working

// This function delivers a template with the error message
function pgerror($string){
include 'head.inc';
echo "<font color=\"#FF0000\">Error: $string</font>";
include 'foot.inc';
exit();

}

// These functions validate required feilds
if (empty($_POST['first'])){
pgerror('Please enter your first name.');
}
else {
$first = $_POST['first'];
}

if (empty($_POST['last'])){
pgerror('Please enter your last name.');
}
else {
$last = $_POST['last'];
}

if (empty($_POST['address'])){
pgerror('Please enter your address.');
}
else {
$address = $_POST['address'];
}

if (empty($_POST['city'])){
pgerror('Please select your city.');
}
else {
$city = $_POST['city'];
}

if (empty($_POST['state'])){
pgerror('Please enter your state or province.');
}
else {
$state = $_POST['state'];
}

if (empty($_POST['postalcode'])){
pgerror('Please enter your postal code/zip code.');
}
else {
$postalcode = $_POST['postalcode'];
}

if (empty($_POST['country'])){
pgerror('Please select your country.');
}
else {
$country = $_POST['country'];
}

if (empty($_POST['email'])){
pgerror('Please enter your email.');
}
else {
$email = $_POST['email'];
}


if (empty($_POST['phone1'])){
pgerror('Please enter your phone number.');
}
else {
$phone1 = $_POST['phone1'];
}
if (empty($_POST['phone2'])){
pgerror('Please enter your phone number.');
}
else {
$phone2 = $_POST['phone2'];
}
if (empty($_POST['phone3'])){
pgerror('Please enter your phone number.');
}
else {
$phone3 = $_POST['phone3'];
}

if (empty($_POST['gender'])){
pgerror('Please enter your gender.');
}
else {
$gender = $_POST['gender'];
}

if (empty($_POST['why'])){
pgerror('Please complete all required feilds.');
}
else {
$why = $_POST['why'];
}

if (empty($_POST['reason1'])){
pgerror('Please complete all required feilds.');
}
else {
$reason1 = $_POST['reason1'];
}
if (empty($_POST['reason2'])){
pgerror('Please complete all required feilds.');
}
else {
$reason2 = $_POST['reason2'];
}
if (empty($_POST['reason3'])){
pgerror('Please complete all required feilds.');
}
else {
$reason3 = $_POST['reason3'];
}


$todayis = date("l, F j, Y, g:i a") ;
$subject = 'Participant Application Form';

$notes = stripcslashes("
Name: $first $last\n
Address: $address\n
City: $city\n
Province: $state\n
Postal Code: $postalcode\n
Country: $country\n
Email: $email\n
Phone: $phone1-$phone2-$phone3\n
Gender (1=Male 2=Female): $gender\n
Parent Permission: $party\n
Parent Name: $parentnamefirst\n
Why: $why\n
Reason 1: $reason1\n
Reason 2: $reason2\n
Reason 3: $reason3\n
");

$message = "
$todayis [EST] \n
Message: $notes \n
";
$from = "From: $email\r\n";

mail("[email protected]", $subject, $message, $from);

include 'head.inc';
echo "<font color=\"green\">Thank you for your application!</font>";
include 'foot.inc';
?>

 

Ok apparently i didnt test it well enough... i had it wrong again, im just going to give this one more shot.. ive got the email coming from cgi-mailer and here is my code

 

$todayis = date("l, F j, Y, g:i a") ;

$subject = 'Participant Application Form';

$notes = stripcslashes("
Name: $first $last\n
Address: $address\n
City: $city\n
Province: $state\n
Postal Code: $postalcode\n
Country: $country\n
Email: $email\n
Phone: $phone1-$phone2-$phone3\n
Gender (1=Male 2=Female): $gender\n
Parent Permission: $party\n
Parent Name: $parentnamefirst\n
Why: $why\n
Reason 1: $reason1\n
Reason 2: $reason2\n
Reason 3: $reason3\n
");

$message = "
$todayis [EST] \n
Message: $notes \n
";
$from = "From: $email\r\n";

mail('[email protected]', $subject, $message);
mail('[email protected]', $subject, $message);

include 'head.inc';
echo "<font color=\"green\">Thank you for your application!</font>";
include 'foot.inc';
?>

 

When i change it to

mail('[email protected]', $subject, $message, $from);

the email wont send at all for some reason

The From: email address needs to be an email address hosted at the sending mail server. When you tested without a value in the 4th parameter, it used a default email address that was probably valid for the sending mail server.

 

You should put any email address entered on the form into the Reply-to: address and set the From: address to be a valid address on the sending mail server.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.