PHP form is not emailing where it should be

We had someone set us up to do a membership site and everything is working perfectly except the email is not going out to notify us that someone has registered. Here is the code for the mailing. I know nothing on PHP so any help is greatly appreciated. The guy that set it up is not available to help for a couple weeks.

// mail user their information
 
    $yoursite = 'www.mycltcassistant.com';
    $webmaster = 'My CLTC Assistant Customer Service';
    $youremail = 'customerservice@ltcconnection.com';
 
    $subject = "You have successfully registered at $yoursite...";
    $message = "Dear $firstname $lastname, you are now subscribed to My CLTC Assistant.
    To login, simply go to http://www.mycltcassistant.com/Protected/client_home.php and enter in the following details in the login form:
    Username: $email
    Password: $password
 
    Please print this information out and store it for future reference.
 
    Thanks,
    $webmaster";
    
    mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
    $_SESSION['username'] = "$email";
    
    // mail information to billing
    
    $BillingEMail = 'billing@ltcconnection.com, amy@ltcconnection.com, jdove@ltcconnection.com';
    $subject = 'User Successfully Subscribed to My CLTC Assistant';
    $message = "A user successfully subscribed to My CLTC Assistant.  See below for information regarding this subscription.
    
    First Name:       $firstname
    Last Name:        $lastname
    Billing Address:  $billingaddress
    Billing City:     $billingcity
    Billing State:    $billingstate
    Billing Zip:      $billingzip
    Phone:            $phone
    Fax:              $fax
    E-Mail:           $email
    Password:         $password
    Credit Cart Exp:  $ccexpmonth / $ccexpyear
    Card Type:        $cctype
    Card Number:      xxxx $cardnumberlast4
    PayFlow Profile:  $ppfprofileid
    Discount Code:    $discountcode
    Course ID:        $courseid";
    
    mail($BillingEMail, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

Open in new window

katleesAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

hieloCommented:
Do you get any errors? What do you see once you submit the completed form? The only thing that is missing from that code is that line 1 should start with:
<?php

and line 45 should be:
?>

but not sure if you just chose not to include it.
0
katleesAuthor Commented:
The code is taken from the middle of the coding. No errors. Everything gets posted to the database, paypal gets the information and paypal sends us an email, but these emails don't go. Attached is all the PHP code on the page
<?php
 
// Constants
$subscription_amount = '49.95';
$currency = 'USD';
$PFPTRANSPath = '/home/mycltcas/public_html/Protected/PFPTransaction.exe';
 
// Login credentials
$user = 'XXXXX';
$vendor = 'XXXX';
$partner = 'PayPal';
$PayPalPassword = 'xxxxx';
 
// Change to Live if you want to post to the live servers.
// $env = 'Test';
$env = 'Live';
$order_num = date('ymd-H').rand(1000,9999);		
 
if ($_REQUEST) 
{
	if (isset($_REQUEST['x']))
	{
		$action = $_REQUEST['x'];
	}
	else
	{
	    $action = "";
	}
}
else
{
	$action = "";
}
 
$paypal = 'USER='.$user.'&VENDOR='.$vendor.'&PARTNER='.$partner.'&PWD='.$PayPalPassword;
 
if($env=='Live')
{
	$submiturl = 'https://payflowpro.verisign.com';
}
else
{
	$submiturl = 'https://pilot-payflowpro.verisign.com';
}
 
session_start();
$message = "";
 
switch ($action)
{
 
case 'do_subscription':
    
    //Database Information
 
    $dbhost = "localhost";
    $dbname = "mycltcas_Membership";
    $dbuser = "mycltcas_mycltc";
    $dbpass = "dove11";
 
    //Connect to database
 
    mysql_connect ( $dbhost, $dbuser, $dbpass)or die("Could not connect: ".mysql_error());
    mysql_select_db($dbname) or die(mysql_error());
    
    $firstname = $_POST['fname'];
    $lastname = $_POST['lname'];
    $billingaddress = $_POST['billing_address'];
    $billingcity = $_POST['billing_city'];
    $billingstate = $_POST['billing_state'];
    $billingzip = $_POST['billing_zip'];
    $email = $_POST['email'];
    
    $discountcode = $_POST['discountcode'];
    $courseid = $_POST['courseid'];
    $discount_taken = 0;
    
    if ($discountcode != "")
    {
        if ($courseid == "")
        {
            $message = "<p><div class='BodyText'><b>If using a Discount Code, Course ID can't be blank</b></div></p>";
            break;
        }
    }
    
    if ($courseid != "")
    {
        $badcourseidformat = 0;
        $courseidlen = strlen($courseid);
        $courseidvfound = 0;
        
        if ($courseidlen < 6)
        {
            $badcourseidformat = 1;
        }
        else
        {
            for ($i = 0; $i < $courseidlen; $i++)
            {
                if (!is_numeric(substr($courseid, $i, 1)))
                {
                    if ((($i + 2 != $courseidlen) && ($i + 3 != $courseidlen)) ||
                        (substr($courseid, $i, 1) != "v" && substr($courseid, $i, 1) != "V") ||
                        $courseidvfound == 1)
                    {
                        $badcourseidformat = 1;
                    }
                    else
                    {
                        $courseidvfound = 1;
                    }
                }
            }
            
            if ($courseidvfound == 0)
            {
                $badcourseidformat = 1;
            }
        }
            
        if ($badcourseidformat == 1)
        {
            $message = "<p><div class='BodyText'><b>You specified a Discount Id, but the Course ID was invalid.</b></div></p>";
            break;
        }
             
        // Look up discount in database        
        $checkdiscount = mysql_query("SELECT * FROM Discount WHERE Code='$discountcode'");
        $discount_exist = mysql_num_rows($checkdiscount);
 
        if($discount_exist > 0)
        {
            $hash = mysql_fetch_assoc($checkdiscount);
            
            $subscription_amount = $subscription_amount - $hash['Amount'];
            $discount_taken = 1;
        }
        else
        {
            $message = "<p><div class='BodyText'><b>Discount ID was not on file.</b></div></p>";
            break;
        }
    }           
        
    /*  Do not hash so we can e-mail their password later - DWW
    $password = md5($_POST['pass1']);
    $passwordunencrypted = $_POST['pass1'];
    */
    
    $password = $_POST['pass1'];
    
    $phone = $_POST['phone'];
    $fax = $_POST['fax'];
    $cctype = $_POST['cctype'];
    $cardnumber = str_replace(' ','',$_POST['cardnumber']);
    $cardnumberlast4 = substr($cardnumber, -4);
    $ccexpmonth = $_POST['expmonth'];
    $ccexpyear = $_POST['expyear'];
    
    $expiry = $ccexpmonth.substr($ccexpyear,2,2);
    
    $recur_start_date = date("mdY", mktime(0, 0, 0, date("m"), date("d")+30, date("y")));
    
    // Check to see if already in database
 
    $checkemail = mysql_query("SELECT email FROM Subscribers WHERE email='$email' AND active=1");
    $email_exist = mysql_num_rows($checkemail);
 
    if($email_exist > 0)
    {
        $message = "<p><div class='BodyText'><b>We're sorry, but the e-mail address you specified has already been taken.  You can manage this account by clicking <a href='http://www.mycltcassistant.com/Protected/client_accountinformation.php'>here</a>, or click <a href='http://www.mycltcassistant.com/Protected/subscribe.php'>here</a> to return to the subscription form to subscribe with another e-mail address.</b></div></p>.";
        break;
    }
    
    // Connect to PayFlowPro
   	$data = $paypal.'&TRXTYPE=R&TENDER=C&ACTION=A';
   	$data .= '&PROFILENAME='.$email;
   	$data .= '&ACCT='.$cardnumber;
   	$data .= '&AMT='.$subscription_amount;
   	$data .= '&EXPDATE='.$expiry;
   	$data .= '&START='.$recur_start_date;
   	$data .= '&TERM=0'; //Continue payments until canceled
   	$data .= '&PAYPERIOD=MONT'; //Monthly payments
   	$data .= '&CURRENCY='.$currency;
   	$data .= '&MAXFAILPAYMENTS=1';
   	$data .= '&EMAIL='.$email;
   	$data .= '&OPTIONALTRX=S'; // Initial transaction
   	$data .= '&OPTIONALTRXAMT='.$subscription_amount;
    $data .= '&STREET='.$billingaddress;
    $data .= '&ZIP='.$billingzip;
    
	$trans  = $PFPTRANSPath . ' ';
    $trans .= $submiturl . ' ';
    $trans .= $order_num . ' ';
	$trans .= '"'.$data.'"';
 
 
	/* run transaction, if result blank, return(NULL) */
	@exec($trans, $result);
 
	if($result[0] == NULL)
	{
	    $message = "Result was null";
	    break;
	}
 
    /* For testing
	echo "Result was ";
	echo $result[0];
	exit();
	*/
	
	/* replace any '&' that are surrounded by spaces -- this assumes
	   the '&' isn't a delimiter, but instead part of a message string
	   and converting it to 'ASCII(38)' will prevent the explode function from
	   thinking it's actually a delimiter. */
	   
	$result[0] = str_replace(' & ', ' ASCII(38) ', $result[0]);
 
	/* construct (pfpro) array out of (result) string */
	
	$valArray = explode('&', $result[0]);
 
	foreach($valArray as $val)
	{
  		$valArray2 = explode('=', $val);
  		$pfpro[$valArray2[0]] = str_replace('ASCII(38)', '&', $valArray2[1]);
	}
 
    /* For testing 
    echo "Result code was ";
    echo $pfpro['RESULT'];
    echo "<br/>";
    echo "RPRef was ";
    echo $pfpro['RPREF'];
    echo "<br/>";
    echo "Profile ID was ";
    echo $pfpro['PROFILEID'];
    echo "<br/>";
    echo "Response Message was ";
    echo $pfpro['RESPMSG'];
    echo "<br/>";
    echo "Transaction result code was ";
    echo $pfpro['TRXRESULT'];
    echo "<br/>";
    echo "Transaction PNRef was ";
    echo $pfpro['TRXPNREF'];
    echo "<br/>";
    echo "Transaction Response Message was ";
    echo $pfpro['TRXRESPMSG'];
    echo "<br/>";
    echo "Transaction Auth Code was ";
    echo $pfpro['AUTHCODE'];
    echo "<br/>";
 
    exit();
    */
    
    /* Pretend there's an error for testing  */
    /*
    echo "<font color='#FF0000'><b>An error occurred!  Error was ";
    echo $pfpro['RESPMSG'];
    echo "</b></font><br/>";
    displaySubscriptionForm();
    */
    
    if ($pfpro['RESULT'] != 0)
    {
        $message = "<font color='#FF0000'><b>An error occurred!  Error was ";
        $message .= $pfpro['RESPMSG'];
        $message .=  "</b></font><br/>";
        break;
    } 
    
    if ($pfpro['TRXRESULT'] != 0)
    {
        $message = "<font color='#FF0000'><b>An error occurred!  Error was ";
        $message .= $pfpro['TRXRESPMSG'];
        $message .= "</b></font><br/>";
        break;
    } 
    
    /* Everything's okay - populate the database */
    $ppfprofileid = $pfpro['PROFILEID'];
    $ppftransactionid = $pfpro['TRXPNREF'];
    $ppftransactionauthcode = $pfpro['AUTHCODE'];
    $ppfpaypalrefcode = $pfpro['PPREF'];
 
    if ($discount_taken == 1)
    {
        $query = "INSERT INTO Subscribers (firstname, lastname, billingaddress, billingcity, billingstate, billingzip, phone, fax, email, password, cardexpmonth, cardexpyear, cardtype, cclastfour, active, ppfprofileid, ppftransactionid, ppftransactionauthcode, ppfpaypalrefcode, discountcode, courseid) VALUES('$firstname', '$lastname', '$billingaddress', '$billingcity', '$billingstate', '$billingzip', '$phone', '$fax', '$email', '$password', '$ccexpmonth', '$ccexpyear', '$cctype', '$cardnumberlast4', '1', '$ppfprofileid', '$ppftransactionid', '$ppftransactionauthcode', '$ppfpaypalrefcode', '$discountcode', '$courseid')";
    }
    else
    {
        $query = "INSERT INTO Subscribers (firstname, lastname, billingaddress, billingcity, billingstate, billingzip, phone, fax, email, password, cardexpmonth, cardexpyear, cardtype, cclastfour, active, ppfprofileid, ppftransactionid, ppftransactionauthcode, ppfpaypalrefcode) VALUES('$firstname', '$lastname', '$billingaddress', '$billingcity', '$billingstate', '$billingzip', '$phone', '$fax', '$email', '$password', '$ccexpmonth', '$ccexpyear', '$cctype', '$cardnumberlast4', '1', '$ppfprofileid', '$ppftransactionid', '$ppftransactionauthcode', '$ppfpaypalrefcode')";
    }
    mysql_query($query) or die(mysql_error());
    mysql_close();
    
    // mail user their information
 
    $yoursite = 'www.mycltcassistant.com';
    $webmaster = 'My CLTC Assistant Customer Service';
    $youremail = 'customerservice@ltcconnection.com';
 
    $subject = "You have successfully registered at $yoursite...";
    $message = "Dear $firstname $lastname, you are now subscribed to My CLTC Assistant.
    To login, simply go to http://www.mycltcassistant.com/Protected/client_home.php and enter in the following details in the login form:
    Username: $email
    Password: $password
 
    Please print this information out and store it for future reference.
 
    Thanks,
    $webmaster";
    
    mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
    $_SESSION['username'] = "$email";
    
    // mail information to billing
    
    $BillingEMail = 'billing@ltcconnection.com, amy@ltcconnection.com, jdove@ltcconnection.com';
    $subject = 'User Successfully Subscribed to My CLTC Assistant';
    $message = "A user successfully subscribed to My CLTC Assistant.  See below for information regarding this subscription.
    
    First Name:       $firstname
    Last Name:        $lastname
    Billing Address:  $billingaddress
    Billing City:     $billingcity
    Billing State:    $billingstate
    Billing Zip:      $billingzip
    Phone:            $phone
    Fax:              $fax
    E-Mail:           $email
    Password:         $password
    Credit Cart Exp:  $ccexpmonth / $ccexpyear
    Card Type:        $cctype
    Card Number:      xxxx $cardnumberlast4
    PayFlow Profile:  $ppfprofileid
    Discount Code:    $discountcode
    Course ID:        $courseid";
    
    mail($BillingEMail, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());
 
    /* echo("SQL Insertion Successful"); */
    echo '<html xmlns="http://www.w3.org/1999/xhtml" >';
    echo '<head>';
    echo '<title>My CLTC Assistant&#8482; - Subscribe</title>';
    echo '<link href="includes/styles.css" rel="stylesheet" type="text/css" />';
    echo '<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />';
    echo '</head>';
    echo '<body>';
    echo("<p><div class='BodyText' align='center'><b>You have successfully subscribed to My CLTC Assistant.<br>");
    echo("Your credit card will be charged $subscription_amount per month going forward.<br>");
    echo("Click <a href='http://www.mycltcassistant.com/Protected/client_home.php'>here</a> to continue to the My CLTC Assistant main page.</b></div></p>");
    echo '</body>';
    echo '</html>';
    exit();
     
    break;
 
default:
    
break;
}
 
?>

Open in new window

0
Michael701Commented:
you never setup $email before line 18

mail($email, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

also no quotes needed here;
$_SESSION['username'] = $email;
0
Build an E-Commerce Site with Angular 5

Learn how to build an E-Commerce site with Angular 5, a JavaScript framework used by developers to build web, desktop, and mobile applications.

katleesAuthor Commented:
Can you please tell me the code to fix it. I know nothing about php.
0
hieloCommented:
OK. After examining it, I believe the problem lies else where. It's possible that your SMTP server is not working or the emails may be filtered. Most likely it is your SMTP. To test your server for outgoing mail save the following as test.php, provide valid email addresses and submit. If you don't get any email, the problem is your SMTP server. If your server is hosted by some company, you would need to contact them for support.

<?php
$to      = 'nobody@example.com';
$subject = 'the subject';
$message = 'hello';
$headers = 'From: webmaster@example.com' . "\r\n" .
    'Reply-To: webmaster@example.com' . "\r\n" .
    'X-Mailer: PHP/' . phpversion();
 
mail($to, $subject, $message, $headers);
?>

Open in new window

0
katleesAuthor Commented:
I got an email when I added this code and put in a correct email
0
hieloCommented:
@Michael: The $email variable is set on line 72:
    $email = $_POST['email'];

>>also no quotes needed here;
>>$_SESSION['username'] = $email;
There's nothing wrong with that line

@katlees:
According to the code you posted, some web form is filled and upon submission, it sends the data to this script. If you fill that form with your email address, then you should get the data if your SMTP server is configured correctly. So, it seems to me the emails will be going to the clients. If you want a copy of these emails then modify line 318 to include a Bcc field to you email address, which I did below using the fake email address "you@yourdomain.com":
    mail($email, $subject, $message, "From: $yoursite <$youremail>\nBcc:you@yourdomain.com\nX-Mailer:PHP/" . phpversion());

The same principle would apply to line 344:
mail($BillingEMail, $subject, $message, "From: $yoursite <$youremail>\nBcc:you@yourdomain.com\nX-Mailer:PHP/" . phpversion());

0
hieloCommented:
>>notify us that someone has registered
Oops, I missed that. Follow the instructions on my previous post.
0
katleesAuthor Commented:
So do I need the quotes in the line or not?
>>also no quotes needed here;
>>$_SESSION['username'] = $email;
There's nothing wrong with that line
0
hieloCommented:
Once again, There's nothing wrong with that line. Leave it alone!
0
hieloCommented:
Did you add the Bcc fields? Did it work?
0
katleesAuthor Commented:
Not sure. Having trouble connecting to the server right now. If the email goes to the user, then how come the others wouldn't get their emails?
 // mail information to billing
    
    $BillingEMail = 'billing@ltcconnection.com, amy@ltcconnection.com, jdove@ltcconnection.com';
    $subject = 'User Successfully Subscribed to My CLTC Assistant';
    $message = "A user successfully subscribed to My CLTC Assistant.  See below for information regarding this subscription.
    
    First Name:       $firstname
    Last Name:        $lastname
    Billing Address:  $billingaddress
    Billing City:     $billingcity
    Billing State:    $billingstate
    Billing Zip:      $billingzip
    Phone:            $phone
    Fax:              $fax
    E-Mail:           $email
    Password:         $password
    Credit Cart Exp:  $ccexpmonth / $ccexpyear
    Card Type:        $cctype
    Card Number:      xxxx $cardnumberlast4
    PayFlow Profile:  $ppfprofileid
    Discount Code:    $discountcode
    Course ID:        $courseid";
    
    mail($BillingEMail, $subject, $message, "From: $yoursite <$youremail>\nX-Mailer:PHP/" . phpversion());

Open in new window

0
hieloCommented:
>>Having trouble connecting to the server right now
Like I said, it could be an SMTP issue.

>>If the email goes to the user, then how come the others wouldn't get their emails?
Excellent point. But the user's email is sent first! If the SMTP server remains does not die, one should follow the other. Even though it is possible that after one email is sent the SMTP server would "die" before you get to the other mail() request, it is highly unlikely that this would happen everytime. It seems to me your SMTP server is the problem.

You have successfully subscribed to My CLTC Assistant.
0
katleesAuthor Commented:
What should I tell them to look for on the SMTP server?
0
hieloCommented:
Before you contact them, submit the test mail script that I supplied above at some random intervals and see if you get them all.
On another note, do you know of the individuals that were supposed to get the Billing info checked for the emails in their spam folder!

If it's in the spam folder, remove the X-Mailer header. In other words change your code to this:
 mail($email, $subject, $message, "From: $yoursite <$youremail>\nBcc:you@yourdomain.com");

The same principle would apply to line 344:
mail($BillingEMail, $subject, $message, "From: $yoursite <$youremail>\nBcc:you@yourdomain.com");

Some spam filters send emails that come from scripts directly to the spam folder.
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
katleesAuthor Commented:
Sorry it took so long to accept. Thanks for your help
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.