Quantcast
Channel: PHP Freaks: PHP Help
Viewing all articles
Browse latest Browse all 13200

Help with two functions and emails

$
0
0

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

 

 


Viewing all articles
Browse latest Browse all 13200

Trending Articles