I love Pokemon
Posts: 14
88 credits Members referred : 0
« on: Aug 08, 2006, 05:15:30 PM »
This is GREAT script and would seem to solve an ongoing problem I have w/ a textbox/checkbox email program for internal club use.
What I don't understand is how to implement this between my CONTACT page (information collection & submit) and my sender page (actually sending the emails.).
Thanks, --Larry
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6349
38918 credits Members referred : 374
It's time to use PHP5!
« Reply #1 on: Aug 08, 2006, 05:30:17 PM »
try this:
Code:
<?php if (check_empty_fields()) { header("Location: your_mail_script.php"); }
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #2 on: Aug 08, 2006, 11:46:46 PM »
UFF-DAH. Thanks Olaf, but I'm dense here.
On "submit" the contact form "POSTS" information to the mailer. All works well, but the email goes out whether or not data boxes are filled.
Session indicators must go berfore the headers, and the fucnction can go about anywhere, but I don't see how check_empty_fields() is called or knows when to actually call the mailer.
This page (CONTACT.php) is password protected, only available to members of the car club. It reads in member data from a mySQL file and allows checking memember names for whom to send emails. I pass this ivormation to SENDER.php which uses the Swift Mailer to send stmp email. The (somewhat awkward) code follows:
<title>New Page 1</title> <td> <h1 align="left"> Contact the Club </h1>
<body>
<div><b><bold> <label for="name">Your Name: </label></b></bold><br> <input type="text" name="name" id="name" size="35"> <font color ="red"> Message will not transmit without a NAME entry </div> </font>
<div> <br><b><bold> <label for="subject">Subject: </label></b></bold><br> <input type="text" name="subject" id="subject" size ="39"> <font color ="red"> Message will not transmit without a SUBJECT entry </div> </font>
<br><br> <b> Select Addressees: <p>
</b> </div>
<? include("dbinfo.inc.php"); mysql_connect('localhost',$username,$password); @mysql_select_db($database) or die( "Unable to select database"); $query="SELECT * FROM rosterlist"; $result=mysql_query($query);
$mailer = new Swift(new Swift_Connection_SMTP('smtp.gmail.com', SWIFT_SECURE_PORT, SWIFT_TLS));
//If anything goes wrong you can see what happened in the logs if ($mailer->isConnected()) //Optional {
//You can call authenticate() anywhere before calling send() if ($mailer->authenticate($username, $password)) { if(isset($_POST['submit']))
$emailadd=$_POST['emails'];
//Sends a simple email
$mailer->send( $emailadd, $name, $subj, $mess .' ------ ' .'This message was originated by ' . $name);
echo "Thank you " . $name . ". The email was sent. ";
} else echo "Didn't authenticate to server";
//Closes cleanly... works without this but it's not as polite. $mailer->close();
?> <br><br><br> <td align="center"><p><a href="members1.php">CLICK HERE TO PROCEED BACK TO THE MEMBERS PAGE</a></p> <? } } else echo "The mailer failed to connect. Errors: <pre>".print_r($mailer->errors, 1)."</pre><br /> Log: <pre>".print_r($mailer->transactions, 1)."</pre>";
?>
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6349
38918 credits Members referred : 374
It's time to use PHP5!
« Reply #3 on: Aug 09, 2006, 12:40:53 AM »
The problem is that you post the form to ther mailer script, post the form to you contact.php and then the redirect will work.
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #4 on: Aug 09, 2006, 02:08:07 AM »
You wrote: ...The problem is that you post the form to ther mailer script, post the form to you contact.php and then the redirect will work.... ?? I don't think you mean I should post back to CONTACT, it is the orginator.
I am posting my contact form to my sender which then calls the Swift mailer. Are you saying that I should POST the contact form to a MTCHECK file (which contains the 'Check empty fields ver 1.01 script). It will then either redisplay the incorrect form or call SENDER?
I appreciate your advice!
--Larry
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6349
38918 credits Members referred : 374
You wrote: ...The problem is that you post the form to ther mailer script, post the form to you contact.php and then the redirect will work.... ?? I don't think you mean I should post back to CONTACT, it is the orginator.
I am posting my contact form to my sender which then calls the Swift mailer. Are you saying that I should POST the contact form to a MTCHECK file (which contains the 'Check empty fields ver 1.01 script). It will then either redisplay the incorrect form or call SENDER?
I appreciate your advice!
--Larry
No, it can't because the data is not saved...
You have to use this form like before and you have to add the validation code into the mail script page:
if valid process mail code else redirect back to the mail script or showing some error...
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #6 on: Aug 09, 2006, 02:15:33 AM »
OK - I'll see if I can figure out where to imbed it. Any suggestions you might have would not be considered
intrusive
Thanks again.
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #7 on: Aug 09, 2006, 02:35:04 AM »
Well, I'm in trouble already. I put the script at the VERY top of CONTACT and receive this session warning:
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at C:\MBMGCC.org\contact.php:2) in C:\MBMGCC.org\contact.php on line 3
SESSION START is line 2
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #8 on: Aug 09, 2006, 02:37:50 AM »
I called for help too soon. There was a blank line above the initial <?PHP.
thanks
I love Pokemon
Posts: 14
88 credits Members referred : 0
« Reply #9 on: Aug 09, 2006, 02:54:39 AM »
Olaf, I've included the script at the top of my CONTACT from, but of course, nohting changes if I leave an input blank.
Could you give me a quick explanation of the last few lines of the script & which of these I change for my application?
Thanks!
if (isset($_POST['submit'])) check_empty_fields(); // and the form field like: // echo <input type=\"text" name=\"_name\""; // if (isset($_POST['_name'])) echo " value=\"".$_POST['_name']."\""; // if (!$_SESSION['_name']) echo " class=\"invalid\">";
Moderator Community Supporter?
Jedai Sword Master
Gender:
Posts: 6349
38918 credits Members referred : 374
Olaf, I've included the script at the top of my CONTACT from, but of course, nohting changes if I leave an input blank.
Could you give me a quick explanation of the last few lines of the script & which of these I change for my application?
Thanks!
if (isset($_POST['submit'])) check_empty_fields(); // and the form field like: // echo <input type=\"text" name=\"_name\""; // if (isset($_POST['_name'])) echo " value=\"".$_POST['_name']."\""; // if (!$_SESSION['_name']) echo " class=\"invalid\">";
since you have to post the form to the mail script you validate the values inside you mailscript