Jump to content

Appending Sender Name to Subject Line


CCAA

Recommended Posts

I wrote a PHP form that was supposed to add the submitter's name at the beginning of the subject line when it was emailed to me. For a few weeks the form worked perfectly; then, without my having made any changes, the sender name was no longer appended to the subject line, and all incoming mail arrived under the same generic header: an annoying development, since the forms in question were application forms and I wanted to be able to quickly identify the registrants as they came in.

 

I've still go no idea what went wrong, since everything else appears to be working. I've had a few complaints that the PayPal window that the code is supposed to generate at the end of the process isn't working, either, but that appears to be a case-by-case thing, as we've had other payments successfully come through and I've tested it on several computers with no problems.

 

Here's the code in question. Any help would be appreciated.

 

<!--This bit here validates the Captcha-->
<?php
require_once('recaptchalib.php');
$privatekey = "private key";
$resp = recaptcha_check_answer ($privatekey,
$_SERVER["REMOTE_ADDR"],
$_POST["recaptcha_challenge_field"],
$_POST["recaptcha_response_field"]);
if (!$resp->is_valid) {
die ("Incorrect value for anti-spam validation. (The \"Are you Human?\" box) Please go back and try it again." .
"(reCAPTCHA said: " . $resp->error . ")");
}
?>

<!--Document proper begins here-->
<?php

//set the email headers here.

$headers = "From: The organization name <[email protected]>\r\n";
$headers .= "Reply-To: The organization name <[email protected]>\r\n";

//set the email address here.
//example
//$email = "[email protected]";

$email = "[email protected]";


//set the email subject line here.
//example
//$subject = "Order";

$subject = $name." Event Name Application ";


// next, loop through the $_POST array, set $message = to the values of the array and a newline for formatting.
foreach($_POST as $key => $value)

$name=$_POST ['name'];
$organization=$_POST ['organization'];
$saddress=$_POST ['saddress'];
$scity=$_POST ['scity'];
$sstate=$_POST ['sstate'];
$szip=$_POST ['szip'];
$maddress=$_POST ['maddress'];
$mcity=$_POST ['mcity'];
$mstate=$_POST ['mstate'];
$mzip=$_POST ['mzip'];
$wphone=$_POST ['wphone'];
$hphone=$_POST ['v'];
$cphone=$_POST ['cphone'];
$other=$_POST ['other'];
$remail=$_POST ['email'];
$website=$_POST ['website'];
$requirements = $_POST ['requirements'];
$bio = $_POST ['bio'];
$payment = $_POST['payment'];
$spaces = $_POST['spaces'];

//if they're a member, the price is 50; if they're a non-profit, it's free; else, the price is 75.
if(isset($_POST['member'])) {
$amount=50;}
elseif($payment=="free"){
$amount=0;
}
else{
$amount=75;
}

//if they register for more than one space, multiply the price by the number of spaces.
if($_POST['spaces'] > 1){
$amount = $amount * $_POST['spaces']; 
}

//if they paid for electricity, add $15 to the amount
if ($_POST['electricity']) {
$amount = $amount + 15;
$electricity = $_POST['electricity'];
}

$message = $name." is registering ".$organization." for RAF 2010 and paying with ".$payment.
"\nBusiness (If Applicable): ".$organization.
"\nEmail Address: ".$remail.
"\nStreet Address: ".$saddress." \t".$scity."\t".$sstate."\t".$szip.
"\nMailing Address: ".$maddress." \t".$mcity."\t".$mstate."\t".$mzip.
"\nWork Phone: ".$wphone." \t Home Phone: ".$hphone." \t Cell Phone: ".$cphone." \t Other Phone: ".$other.
"\nWebsite: ".$website.
"\nBio: ".$bio.
"\nSpaces: ".$spaces.
"\nRequirements: ".$requirements
;


if ($_POST['electricity']) {
$message = $message. " Electricity? " .$electricity;
}

//send the email
if (empty($remail)) {
    echo 'An email address is required. Please return to the form and enter your email address.';
exit;
}

elseif(empty($payment)) {
echo 'A payment method is required. Please return to the form and choose a payment method. If you\'re a non-profit and will not be selling anything at your booth, select "Not Applicable".';
exit;
}

else{
mail($email, $subject, $message, $headers);
mail($remail, $subject, $message, $headers); //send a copy to the registrant
}

if($payment==paypal){

?>


<html><head>
<script language="JavaScript" type="text/javascript">
<!--
function submitForm() {
document.RAFPayPalForm.submit();
setTimeout( "window.location.href = 'http://www.example.org'", 5*1000 ); 
}
//-->
</script>
</head>

<body onLoad="javascript:submitForm()">
Transferring you to Pay Pal to complete registration...

<form name="RAFPayPalForm" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="business" value="business #">
<input type="hidden" name="cmd" value="_xclick">
<input type="hidden" name="lc" value="US">
<input type="hidden" name="button_subtype" value="products">
<input type="hidden" name="no_note" value="1">
<input type="hidden" name="no_shipping" value="1">
<input type="hidden" name="rm" value="1">
<input type="hidden" name="return" value="http://www.example.org">
<input type="hidden" name="item_number" value="Event registration">
<input type="hidden" name="currency_code" value="USD">
<input type="hidden" name="amount" value="<? echo $amount ?>">
<input type="hidden" name="item_name" value="<? echo $name ?> Event Registration: <? echo $spaces ?> Spaces <? if ($_POST['electricity']) { echo "With Electricity";} ?> ">
</form>
</body>
</html>

<?php
}
elseif ($payment==free){
echo "Thank you $organization for registering for Event Name. A confirmation email has been sent to you with the details of your registration.<br />
<a href=\"http://www.example.org\">Return to the Example Website</a>";
}
else{
echo "Thank you for registering for River Artsfest 2010. A confirmation email has been sent to you with the details of your registration.<br />
Please mail your <strong> \$$amount check </strong> to: CCAA, PO Box 697, White Plains, MD 20695<br />
<a href=\"http://www.example.org\">Return to the Example Website</a>";
}
?>

Link to comment
https://forums.phpfreaks.com/topic/204303-appending-sender-name-to-subject-line/
Share on other sites

Brilliant. It works perfectly now.  :D

 

Are global variables something that the hosting company would control on a shared server? I don't remember fiddling with anything like that, and it would make sense that it stopped working if my host changed something in their setup. That or I did turn it off at some point and have no recollection whatsoever. I'm still a novice at this whole PHP thing.

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.