vendredi 20 avril 2018

How to put an if statement in a php mailer

I am attempting to put an if/else statement in the body of a php mailer email. The reason I am doing this is so that I don't have to create multiple $mail->Body togs based on the variable $rsvp_answer.

Does anyone see what I am doing wrong and how I can get this to work correctly?

$mail->isHTML(true);                                  // Set email format to HTML

        $mail->Subject = $subject;
        $mail->Body    = '
            <head>
            <style>
            #nameSec {
                margin: 0 auto 50px 0;
                text-align: center;
            }
            .fancyFontTitle {
                font-size: 5rem;
                line-height: 1.5em;
                color: #333;
                font-family: cursive;
            }
            #weddingDate, .title {
                font-family: sans-serif;
                font-size: 2.5rem;
            }
            .title {
                margin: 0px auto 50px auto;
                text-align: center;
                color: #2E393F;
            }
            </style>
            </head>
            <body>
                <div id="header-background" style="background:#C8DBD9;width:100%;max-width:100%;height:auto;">
                    <div id="email-header" style="width:600px;height:auto;margin:auto;display:block;padding:20px 0;">
                        <div id="nameSec">
                            <span class="fancyFontTitle"></span><br>
                        </div>
                    </div>
                    <div id="email-link" style="width:100%;padding:15px;height:auto;background:#EBEBEB;position:relative;">
                        <div id="email-link-container" style="width:600px;height:auto;margin:auto;text-align:left;position:absolute;top:50%;left:50%;-webkit-transform:translate(-50%, -50%);transform: translate(-50%, -50%);width:600px; font-family:Helvetica Neue,Helvetica,Arial,sans-serif;font-size:1.1em;">\
            '
            if ($rsvp_answer == 'Yes') { '
                            <p>' . $rsvp_name . '</p>
                            <p>' . $rsvp_email . '</p>
                            <p>Will the guest be attending: ' . $rsvp_answer . '</p>
                            <p>Will they bring a guest: ' . $rsvp_guest_answer . '</p>
                            <p>Guest 1: ' . $guest1 . '</p>
                            <p>Guest 2: ' . $guest2 . '</p>
                            <p>Guest 3: ' . $guest3 . '</p>
            ' else {
                '           <p>Sorry you cant attend. </p>
            }               
                        </div>
                    </div>
                </div>
            </body>
        ';
        $mail->AltBody = 'Proposal Request Sent';
        if(!$mail->send()) {
            echo 'Message1 could not be sent.';
            echo 'Mailer Error: ' . $mail->ErrorInfo;
        } else {
            echo 'Message has been sent';
        }

Aucun commentaire:

Enregistrer un commentaire