johnnys2 Posted August 13, 2013 Share Posted August 13, 2013 Hi Guys, I hope somebody can help me out. I've tried to figure this out by myself the past few weeks, but can't! Newbie to php, taking over project from somebody else. I have an online form that users fill in, this info is sent via email to myself successfully (Admin). I would like instead to send multiple emails - one to Admin saying 'User xyz has filled out the form below' AND one sent to the User saying 'Thank you for filling out the form below' AND one sent to Support saying 'User xyz has requested for support please see below' So three different email bodys and three different recipients. All I have currently is a common.php page with two functions (one for each email form I presume), and a form.php page with the actual html form (and some php code). First function in common.php function sendEmailToAdmin($make, $model, $isSetupHelpReqd){ $isSetupHelpReqd = (isset($isSetupHelpReqd) && $isSetupHelpReqd =='1') ? 'yes' : 'no'; $HTMLmessage1 = "<font color=#4284B0 face=Arial size=4><strong>".$GLOBALS["app-name"]."</strong></font><br /> \n <p>Admin, please see the form below.</p> <table> <tbody> <tr> <td>Make:</td> <td>".$make."</td> </tr> <tr> <td>Model:</td> <td>".$model."</td> </tr> <tr> <td>Setup Request:</td> <td>".$isSetupHelpReqd."</td> </tr> </tbody> </table> <hr />".$GLOBALS["appurl"]." "; require("scripts/phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = $GLOBALS["smtp_server"]; $mail->SMTPAuth = false; $mail->IsHTML(true); $mail->From = $GLOBALS["emailsenderaddress"]; $mail->FromName = $GLOBALS["emailsendername"]; $mail->Body = $HTMLmessage1; $mail->AltBody = "This email is in HTML format please view in HTML mode"; $mail->Subject = "Form Submission - Request"; $mail->AddAddress("admin@something.com"); // this sends the email to Net Services if(!$mail->Send()){ return false; }else{ return true; } } // end sendEmailToAdmin Function Second function in commpn.php function sendEmailToSupport($make, $model, $isSetupHelpReqd){ $isSetupHelpReqd = (isset($isSetupHelpReqd) && $isSetupHelpReqd =='1') ? 'yes' : 'no'; $HTMLmessage2 = "<font color=#4284B0 face=Arial size=4><strong>".$GLOBALS["app-name"]."</strong></font><br /> \n <p>Support has been requested, please see the form below.</p> <table> <tbody> <tr> <td>Make:</td> <td>".$make."</td> </tr> <tr> <td>Model:</td> <td>".$model."</td> </tr> <tr> <td>Setup Request:</td> <td>".$isSetupHelpReqd."</td> </tr> </tbody> </table> <hr />".$GLOBALS["appurl"]." "; require("scripts/phpmailer/class.phpmailer.php"); $mail = new PHPMailer(); $mail->IsSMTP(); $mail->Host = $GLOBALS["smtp_server"]; $mail->SMTPAuth = false; $mail->IsHTML(true); $mail->From = $GLOBALS["emailsenderaddress"]; $mail->FromName = $GLOBALS["emailsendername"]; $mail->Body = $HTMLmessage2; $mail->AltBody = "This email is in HTML format please view in HTML mode"; $mail->Subject = "Request Completed - Assistance Requested"; $mail->AddAddress("support@something.com"); if(!$mail->Send()){ return false; }else{ return true; } } // end sendEmailToSupport Function I also found this code in the second function commented out, but it never did anything //send copy of form to Support if Setup box is ticked if(isset($_POST['assistance_reqd_for_setup'])&&$_POST['assistance_reqd_for_setup']==1){ $mail->AddAddress("Support@something.com"); $mail->Subject = "Form Submission - Request - Setup"; $mail->Body = $HTMLmessage2; } //end send mail to Support This is the code after my insert query on the form.php page if(sendEmailToAdmin($make, $model,$isSetupHelpReqd)){ $boolMailSent = true; }else{ $boolMailSent = false; } Any guidance or help at all would be much appreciated, apologies for my lack of knowledge and ignorance however I have tried to fix this myself. I've looked at switch statements, if else loops, clearaddress() to send to multiple recipients amongst others. Thanks in advance, J Quote Link to comment Share on other sites More sharing options...
Solution micah1701 Posted August 13, 2013 Solution Share Posted August 13, 2013 after your form, where you call the first function, "sendMailToAdmin()" I think you just need to call the other 2 functions as well and you should be all set, something like: if( sendEmailToAdmin($make, $model,$isSetupHelpReqd) // call the first function ) { $boolMailSent = true; }else{ $boolMailSent = false; } sendEmailToSupport($make, $model,$isSetupHelpReqd); // call the second function it occurs to me that both functions have the line "require("scripts/phpmailer/class.phpmailer.php");" calling it a second time in the second function may error out, you might want to change that to require_once(). Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted August 13, 2013 Author Share Posted August 13, 2013 thanks for this help - ill go give it a try now Quote Link to comment Share on other sites More sharing options...
johnnys2 Posted August 13, 2013 Author Share Posted August 13, 2013 thanks very much micah1701 - that worked! Not until I changed that to require_once() as you advised. Just one more thing now, the two emails send perfectly like I was hoping, however the second email (to Support) sends whether or not the tick box is checked or not? Has it got anything to do with the code below - should I have this somewhere? if(isset($_POST['assistance_reqd_for_setup'])&&$_POST['assistance_reqd_for_setup']==1){ $mail->AddAddress("Support@something.com"); $mail->Subject = "Form Submission - Request - Setup"; $mail->Body = $HTMLmessage2; } Again, thanks v much 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.