PCesarano Posted April 20, 2015 Share Posted April 20, 2015 Hello all...so I am baffled as to why this is not working and am in desperate search of an answer. My code is attached below. So, I have a site that registers followers once they have entered their info (it is a voluntary registration to a historical society). When they register, an email needs to go out to them (receipt) saying basically 'thanks! you joined!' (email 1), then an email needs to go out to the Historical Society itself notifying them of a new member (john smith) registering (email 2). Finally, an email (number 3) also needs to go out which contains the updated email list of members. I did this by writing 3 different php <?php ... ?> functions, but Dreamweaver is only executing the first mail function. So I thought...must have bugged the second function, so to test it, I switched the order of operations between the first and second function, and now the second function works but now the first function does not. Same holds for the third function if it is first in line. I was under the impression that I could have a thousand different php scripts and they would all be executed, but if I do email 1, email 2 doesn't happen, nor email 3, and vice-versa.for any other permutations. So, if someone knows why this is happening, great, please tell me. Alternatively, if someone knows how to call a php script from a different php script could you tell me that? Because I could divide them into script1.php, script2.php, and script3.php and call them consecutively, which may solve the problem. Every script works...its just that executing the first one seems to be causing the others to not execute, and I cannot figure out why. Thanks in advance. Thanks friends. Patrick`<?php $file = 'EmailList.txt'; // Open the file to get existing content $current = file_get_contents($file); // Append a new person to the file $current .= $_POST['Email'].', '; // Write the contents back to the file file_put_contents($file, $current); ?> <?php //New Member Info Reported to the Third DCA HS require('class.phpmailer.php'); $exp_date = date('m-d-Y', strtotime('+1 year')); $msg1 = 'The following individual has completed the payment process and should be entered into the Historical Society database: '."\r\n"."\r\n"; $msg2 = 'You have successfully registered with the Third District Court of Appeal Historical Society. Please review the information below and contact us at thirddcahs@gmail.com if there are any inaccuracies. We thank you for your support.'."\r\n"."\r\n"; $body = 'First Name: '.$_POST['First_Name']."\r\n".'Last Name: '.$_POST['Last_Name']."\r\n".'Middle Initial: '.$_POST['MI']."\r\n".'Firm/Organization: '.$_POST['Organization']."\r\n".'Position: '.$_POST['Position']."\r\n".'Address: '.$_POST['Address']."\r\n".'Address (cont.): '.$_POST['Address_Cont']."\r\n".'City: '.$_POST['City']."\r\n". 'State: '.$_POST['State']."\r\n".'Zip: '.$_POST['Zip']."\r\n".'Phone: '.$_POST['Phone']."\r\n".'Fax: '.$_POST['Fax']."\r\n".'Email: '.$_POST['Email']."\r\n".'Membership Expiration Date (MM-DD-YYYY): '.$exp_date."\r\n".'Amount Paid: $25.00'; $email = new PHPMailer(); $email->From = 'admin@thirddcahistoricalsociety.org'; $email->FromName = 'The Third District Court of Appeal Historical Society'; $email->Subject = $msg1; $email->Body = $body; $email->AddAddress( 'Patrick.Cesarano@gmail.com' ); //$recipients1 = 'phil@parrishappeals.com, paulappeal@aol.com, caliannel@aol.com, cgeorge@cmpg-law.com, admin@thirddcahistoricalsociety.org, dtownsend@parrishappeals.com'; return $email->Send(); ?> <?php //New Member Info Reported to the Enrolling Member require('class.phpmailer.php'); $exp_date = date('m-d-Y', strtotime('+1 year')); $msg2 = 'You have successfully registered with the Third District Court of Appeal Historical Society. Please review the information below and contact us at thirddcahs@gmail.com if there are any inaccuracies. We thank you for your support.'."\r\n"."\r\n"; $body = 'First Name: '.$_POST['First_Name']."\r\n".'Last Name: '.$_POST['Last_Name']."\r\n".'Middle Initial: '.$_POST['MI']."\r\n".'Firm/Organization: '.$_POST['Organization']."\r\n".'Position: '.$_POST['Position']."\r\n".'Address: '.$_POST['Address']."\r\n".'Address (cont.): '.$_POST['Address_Cont']."\r\n".'City: '.$_POST['City']."\r\n". 'State: '.$_POST['State']."\r\n".'Zip: '.$_POST['Zip']."\r\n".'Phone: '.$_POST['Phone']."\r\n".'Fax: '.$_POST['Fax']."\r\n".'Email: '.$_POST['Email']."\r\n".'Membership Expiration Date (MM-DD-YYYY): '.$exp_date."\r\n".'Amount Paid: $25.00'; $email = new PHPMailer(); $email->From = 'admin@thirddcahistoricalsociety.org'; $email->FromName = 'The Third District Court of Appeal Historical Society'; $email->Subject = $msg2; $email->Body = $body; $email->AddAddress( $_POST['Email'] ); //$recipients1 = 'phil@parrishappeals.com, paulappeal@aol.com, caliannel@aol.com, cgeorge@cmpg-law.com, admin@thirddcahistoricalsociety.org, dtownsend@parrishappeals.com'; return $email->Send(); ?> <?php require_once('class.phpmailer.php'); $email = new PHPMailer(); $email->From = 'admin@thirddcahistoricalsociety.org'; $email->FromName = 'The Third District Court of Appeal Historical Society'; $email->Subject = 'Email List'; $email->Body = 'Here is the most recent email list for the Third Districk Court of Appeal Historical Society'; $email->AddAddress = 'Patrick.Cesarano@gmail.com'; //$email->AddAddress( '...' ); $file_to_attach = 'EmailList.txt'; $email->AddAttachment( $file_to_attach , 'Email List' ); return $email->Send(); ?>` Quote Link to comment Share on other sites More sharing options...
Muddy_Funster Posted April 20, 2015 Share Posted April 20, 2015 I really really hope those aren't the actual email addresses of people (this site is crawlable, so they could be en-route for a lot of spam). Rather than trying to call seperate "scripts" it would be easier to wrap them in functions and call the functions one after another. eg: function sendFirstMail(){ ... <First Mail Code> ... return true; } function sendSeconfMail(){ ... <Second Mail Code> ... return true; } function sendThirdMail(){ ... <Third Mail Code> ... return true; } $firstMail = sendFirstMail(); ($firstMail === true) ? $secondMail = sendSecondMail() : print_r("Something went wrong sending the first mail"); ($secondMail === true) ? $thirdMail = sendThirdMail() : print_r("something went wrong sending the second mail"); ($thirdMail === true) ? print_r("All Mail sent successfully" : print_r("something went wrong sending the third mail"); That is a gross oversimplification, but it should be enough for you to work out how to implement it. Quote Link to comment Share on other sites More sharing options...
IThinkMyBrainHurts Posted April 20, 2015 Share Posted April 20, 2015 How are these being used? Are they all in one file? If so, the use of "return" not within a function scope basically acts like exit...http://php.net/manual/en/function.return.php If called from the global scope, then execution of the current script file is ended.As Muddy_Funster demonstrates, use functions to wrap your code (that's when you normally use "return" statements).If you really do want to put them in separate files (but by sounds you want functions!) then use some form of include(), include_once(), require() or require_once() to include the file, anything not within a class or function will be executed straight away. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.